1

Possible Duplicate:
Design of std::ifstream class
Why does (i|o)fstream take a const char* parameter for a file name?

Looking at std::ifstream's constructors, I find two:

ifstream ( );
explicit ifstream ( const char * filename, ios_base::openmode mode = ios_base::in );

Why does the second one take a const char * and not a const std::string &?

Is this some kind of avoidance of circularity or forward reference?

Community
  • 1
  • 1
WilliamKF
  • 41,123
  • 68
  • 193
  • 295

2 Answers2

8

It was a simple omission. Nobody thought about it in time. This has been corrected in C++11, where std::string is also accepted. From 27.9.1.7/3:

explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in);

Effects: the same as basic_ifstream(s.c_str(), mode).

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
0

Your compiler is out of date. Upgrade it and you should find a std::string constructor.

Puppy
  • 144,682
  • 38
  • 256
  • 465