views:

970

answers:

1

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 compiles, instead it throws this exception:

std::ifstream input (fileName);   

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

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

+1  A: 

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

sbi
You're right .. I missed <string>, don't you think this error message is totally misleading. I can't relate this error message with the fix you're mentioned. Very strange!!
Vadi
@Vadi: Very likely `std::string` is defined in some other header you already included, but the operator is not. So the compiler accepts `string s;`, but not the invocation of the stream operator.
sbi