Sign in to follow this  

string class

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, so I decided to take a look at gametutorials.com. And whaddayaknow - I found a solution to a problem I've had for ages relating to string input in my MUD kernel, string input. But as soon as I had written this, "#include <string>", in my "Globals.h" file, and tried to use it like this, "if (strInput == "male" || "Male")", after having declared strInput as this, "string strInput = "";", I got an error stating that string was an undeclared identifier:( Does anyone know why?

Share this post


Link to post
Share on other sites
Quote:
Original post by Afr0m@n
if (strInput == "male" || "Male")
if(strInput == "male" || strInput == "MALE"). There's no operator || defined for char *, or for std::string.

Further, what happens of you get mixed case input, like "Male"? The best solution is to use std::transform along with std::toupper or std::tolower to convert to a single case, and then perform your tests on that.

Share this post


Link to post
Share on other sites
Actually, I've used mix cased input comparison. But thanks to you, I remembered that I'll have to put in another else clause to remind the user of what to write if he/she writes something different. That's easier:D

Anyway, now I get an error stating this:

"C:\Programs\C++\MUD\NewGame.cpp(10) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conver
sion)".

What does this mean? This is how line 10 looks:

"cin >> strInput;"

They use the cin operator to retrieve user input in the gametutorials.com project too, and that project compiles nicely:'( I've always used cin, so I don't know of any other operator that does the same thing:(

And thanks to everyone so far:D

Share this post


Link to post
Share on other sites

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this