Search code examples
c++visual-c++compiler-errorscygwin

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


Please don't confuse with the title as it was already asked by someone but for a different context

The below code in Visual C++ Compiler (VS2008) does not get compiled, instead it throws this exception:

std::ifstream input (fileName);   

while (input) {
  string s;
  input >> s;
  std::cout << s << std::endl;
};

But this code compiles fine in cygwin g++. Any thoughts?


Solution

  • Have you included all of the following headers?

    • <fstream>
    • <istream>
    • <iostream>
    • <string>

    My guess is you forgot <string>.

    On a side note: That should be std::cout and std::endl.