2

In Visual Studio 2010, the following code works, even with the /Za (struct ANSI) compiler flag.

string name = "input.txt";

ifstream fin;

fin.open(name);

All the documentation I can find seems to indicate that you have to pass a C-string to ifstream::open. Is this really ANSI now, or is it a Microsoft extension, and a problem with the /Za flag?

Thanks,

Saul

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
saulspatz
  • 5,011
  • 5
  • 36
  • 47

1 Answers1

8

In C++11, you can pass strings directly. Visual Studio 10 supports this. Prior to C++11, you would have to pass a c-string, which you could do like this:

fin.open(name.c_str());
Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274