Sign in to follow this  

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

This topic is 4260 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

Am I reading right?
...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;
	}
}


Thanks in advance for any answer, good or bad [smile]

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Monder
Are you including... and <string>?


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

Share this post


Link to post
Share on other sites

This topic is 4260 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