Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cin problems with strings

Status
Not open for further replies.

JetongC

Vendor
Nov 14, 2001
1
0
0
US
Can someone help me with this? I am trying to grab a string from the user by doing this:

string word;
...
while(cin >> word){
...
}

Here is the error I'm getting:

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 conversion)

Thanks
 

i would do something along the lines of

string word;

while(word != &quot;done&quot;)
{
cin>>word;
}

this will loop until the user enters &quot;done&quot;

Matt
 
I'd say you've forgotten to add

#include <string>
:) Hope that this helped! ;-)
 
don't forget to initialise ur string to something or u'll have trouble. it should look like this:

String word = &quot;something&quot;;

do
{
cin>> word;
...
}
while(strcmp(word,&quot;quit&quot;));

(strcmp gives zero when they r equal)



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top