String variables with if statements.

closed account (y8h7M4Gy)
Whenever i try to use a string variable with an if statement it turns up as error. Does anybody know why?

Here is the part of my code where the error is:

	string mystr3;
	getline (cin, mystr3);
	string mystr2 (mystr3);
	int myint;
	stringstream(mystr2) >> myint;
	cout << mystr3 << endl;
	if (mystr3 == 'blaa')
	cout << "yay" << endl;
Last edited on
try inverted commas ( "" )

single commas are for use with chars.

I got the same error, and changed to inverted... but then a new stringstream error popped up after that as I'm unsure of the correct declaration of it.

Last edited on
closed account (y8h7M4Gy)
Hmm.. it still doesn't work... I guess ill just have to convert words to number codes...
closed account (y8h7M4Gy)
Okay nevermind I got it.

	string myint;
	string mystr3;
	getline (cin, mystr3);
	string mystr2 (mystr3);
	stringstream(mystr2) >> myint;
	if (myint == "blaa")
	cout << "yay" << endl;
Topic archived. No new replies allowed.