no operator"<<" matches these operands error

-using visual studio 2019
-errors(2):
Error (active) E0349 no operator "<<" matches these operands ConsoleApplication15 C:\Users\18168\source\repos\ConsoleApplication15\ConsoleApplication15\ConsoleApplication15.cpp line 161

Error (active) E0349 no operator "<<" matches these operands ConsoleApplication15 C:\Users\18168\source\repos\ConsoleApplication15\ConsoleApplication15\ConsoleApplication15.cpp line 171



code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#pragma warning(disable : 4996)
#include <iostream>//headerfile
#include <fstream>//headerfile
#include <iomanip>//headerfile
#include <ctime>//headerfile
#include <string>//headerfile
#include <cctype>//headerfile
#include <sstream>

using namespace std;

class BST //binary search tree class
{
private://private class
	struct Node
	{
		string letter;//english string variable
		string code;//morsecode string variable
		Node* left{ NULL };// points to left memory location in tree
		Node* right{ NULL };//points to right memory location in tree
	};
	Node* root;//points root node memory location
public:// public class
	BST()
	{
		root = NULL;//empty tree
	}
	void Insert(Node*& r, string letter, string code)//insert english and morse string into tree
	{
		if (r == NULL)//if node is empty
		{
			r = new Node;//assigns r to new node
			r->letter = letter;//r accesses string letter
			r->left = r->right = NULL; r->code = code;
		}
		if (r->letter > letter) Insert(r->left, letter, code);//accesses the property of left node///
		if (r->letter < letter) Insert(r->right, letter, code);//accesses the property of right node////
	}
	void Insert(string letter, string code)//insert english and morse string into tree
	{
		Insert(root, letter, code);//insert english and morse string into root node
	}
	void DisplayPreOrder(Node* r)//display tree traversal
	{
		if (r != NULL)//if node is not empty
		{
			cout << r->letter << "\t";//display letter node
			DisplayPreOrder(r->left);//display tree traversal
			DisplayPreOrder(r->right);//display tree traversal
		}
	}
	void DisplayInOrder(Node* r)//display tree traversal
	{
		if (r != NULL)//if node is not empty
		{
			DisplayInOrder(r->left);//display tree traversal of left traversal
			cout << r->letter << "\t";
			DisplayInOrder(r->right);//display tree traversal of right traversal
		}
	}
	// Overrides DisplayInOrder(Node * )
	void DisplayInOrder()//display tree traversal functions
	{
		DisplayInOrder(root);//display tree traversal functions
	}
	void DisplayPreOrder()//display tree traversal functions
	{
		DisplayPreOrder(root);//display tree traversal functions
	}
	void DisplayPostOrder(Node* r)//display tree traversal functions
	{
		if (r != NULL)//if node is not empty
		{
			DisplayPostOrder(r->left);//display tree traversal of left traversal
			DisplayPostOrder(r->right);//display tree traversal of right traversal
			cout << r->letter << "\t";//display morse letter
		}
	}
	void Encode(char x)//function to encode morsecode string 
	{
		Node* r = SearchAndReturn(root, x);//points to value returned x 
		if (r != NULL) //if node is not empty
			cout << r->code;
		else cout << "Error.";//display error
	}
	void Decode(string x)//functiont to decode english string
	{
		Node* r = SearchAndReturnString(root, x);//search node r and return string
		if (r->code == x)
			cout << r->letter;
		else
			cout << r->code << " with x being " << x << endl;//display translated sentence or word
		cout << "Error.";//display error to user
	}
	Node* SearchAndReturn(Node* r, char x)//function to search and retreive value in tree
	{
		if (r != NULL)//if node is not empty
		{
			if (r->letter[0] == x) { return r; }
			else if (r->letter[0] > x)
			{
				SearchAndReturn(r->left, x);//search and return left node
			}
			else
			{
				SearchAndReturn(r->right, x);//search and return right node
			}
		}
		else return NULL;//return empty
	}
	Node* SearchAndReturnString(Node* r, string x)//function to search and retreive value in tree
	{
		if (r != NULL)//if node is not empty
		{
			if (r->code == x)
			{
				cout << r->code << " matches " << x << endl; return r;
			}
			else if (r->code > x)
			{
				SearchAndReturnString(r->left, x);//function to search and retreive value in tree
			}
			else
			{
				SearchAndReturnString(r->right, x);//function to search and retreive value in tree
			}
		}
		else return NULL;//return empty
	}
};
struct alphaTree
{
	string letter;//variable string
	string code;//variable string

};
int main()//main fuction
{
	time_t u;//function to display current time
	time(&u);//function to display current time
	cout << ctime(&u) << endl;//function to display current time
	BST t;
	string message;
	char* morseCode = new char;
	char ans;
	alphaTree array[27] = { {"E", ". "}, {"T", "- "}, {"I", ".. "}, {"A", ".- "}, {"N", "-. "}, {"M", "-- "},//tree containing character and their morsecode translation
	{"S", "... "}, {"U", "..- "}, {"R", ".-. "}, {"W", ".-- "}, {"D", "-.. "}, {"K", "-.- "},//tree containing character and their morsecode translation
	{"G", "--. "}, {"O", "--- "}, {"H", ".... "}, {"V", "...- "}, {"F", "..-. "}, {"L", ".-.. "},//tree containing character and their morsecode translation
	{"P", ".--. "}, {"J", ".--- "}, {"B", "-... "}, {"X", "-..- "},//tree containing character and their morsecode translation
	{"C", "-.-. "}, {"Y", "-.-- "}, {"Z", "--.. "}, {"Q", "--.- "}, {" ", "---- "} };//tree containing character and their morsecode translation
	t.Insert("0", "");
	for (int i = 0; i < 27; i++)                 //for loop for character insertions into tree
	{
		t.Insert(array[i].letter, array[i].code);       //insert function into tree
	}
	do {
		cout << "Enter your message: ";          //ask the user to enter their message to be decoded
		getline(cin, message);                   //extracts characters from string
		for (int i = 0; i < message.size(); i++)                 //convert string to upper case for loop
		{
			cout << t.Encode(message[i]) << ' ';
		}
		cout << endl;

		cout << "Enter your Morse code, separated by spaces: "; //ask user to enter morsecode to be encoded
		string morseCode;
		getline(cin, morseCode);                 //extracts characters from string
		istringstream is(morseCode);
		string token;
		while (is >> token) {
			cout << t.Decode(token);
		}
		cout << '\n';
		cout << "Continue: ";
		cin >> ans;
		cin.ignore();
		cout << endl;
	} while (ans == 'y');
	return 0;
}
Last edited on
> void Encode(char x)//function to encode morsecode string
...
> void Decode(string x)//functiont to decode english string
...
cout << t.Encode(message[i]) << ' ';
...
cout << t.Decode(token);

They both return void, so there is nothing to do.
Plus they both do their own cout thing anyway.

Perhaps just call them
1
2
 t.Encode(message[i]);
cout << ' ';


and
t.Decode(token);
Alternatively you could modify Encode and Decode so they return what they encoded or decoded, and don't display anything themselves.

This works better for me; I expect a function called Encode to return me the result of the encoding process.

To get this to work neatly you would need to work out how to handle errors based on the return values.

Andy
Topic archived. No new replies allowed.