View Single Post
  #15 (permalink)  
Old 03-28-2007, 04:34 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up Re: VC++ Tips & Tricks

Compiler Problem

My compiler(VC++ 6) never accepts cin >> str1 if str1 is declared as a string .
the following program gives error.
#include <iostream.h>
#include <string>

using namespace std;

int main() {
string testStr;
cout << "enter string";
cin >> testStr;

return 0;
}


C:\Program Files\Microsoft Visual Studio\MyProjects\Learning\test2\test_loop.cpp(9) : 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::allo
cator<char> >' (or there is no acceptable conversion)
Solutions :

Change "#include <iostream.h>" to "#include <iostream>". Use the newer standard headers such as iostream, string and fstream instead of iostream.h, string.h and fstream.h. Mixing older and new style headers causes compilation problems such as I experienced.


thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Reply With Quote