Click to See Complete Forum and Search --> : help... error with string


Sunkal
January 14th, 2003, 08:45 AM
hi, i am just going through accelerated cpp. Using VC, I have written the below code as a console application :

#include <iostream.h>
#include <string>

using namespace std;
int main()
{
string name;
cout << "enter ur name " << endl;
cin >> name;
return 0;
}


On compilation, getting the below error for cin >> name; its exactly as the book says. What is happening here.. please help!!!

f:\sunita\work\helloo\helloo.cpp(8) : 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

Philip Nicoletti
January 14th, 2003, 09:02 AM
It should be :


#include <iostream> // no .h


You should you the standard headers, not the
old-style headers from before ISO standardization.

Sunkal
January 14th, 2003, 09:06 AM
thanks for pointing it out to me..

Graham
January 14th, 2003, 11:19 AM
... and if the book you're using does have iostream.h in its examples, ditch it and get a book by someone who knows what he's talking about.