Public Group

# WTF you can't send a std::string to cout?

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

## Recommended Posts

...error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)



bool CMyEngine::CheckFor(string value)
{
string a;
cin >> a;
if(a == value)
{
return true;
}
else
{
return false;
}
}



##### Share on other sites
std::cout uses operator<<, so you'd need to do something like

std::cout << myString << std::endl;

operator>>, however, is defined by std::cin and the usage you've shown in the bottom example appears to be correct.

##### Share on other sites
Are you including iostream.h and string.h or iostream and string? You need to include the latter, the former are pre-standard header and should not be used.

Also using >> to get a string from cin will only read a single word so if you do cin >> foo and you type in "la la la" foo will just contain "la".

##### Share on other sites
I remember that there was such a problem in VC6 with cout, it was fixed in .NET.

If you're using .NET, my guess would be that it doesn't accept it with cin because you can't specify a maximum string length just by passing a string. In that case you would need to use getline() or another such function.

##### Share on other sites
Quote:
 Original post by MonderAre you including... and ?

There's always an easy answer...Thanks, and may I never forget to include <string> again...[smile].

• 33
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631353
• Total Posts
2999488
×