Why does this produce an error? File I/O

I'm wondering why the following pattern is incorrect:

string filename = "myfile.txt";
ifstream input(filename);

But

ifstream input("myfile.txt");

or

char a[] = "myfile.txt";
ifstream input(a);

do? How can I make the first case work without creating any array or having to know the value of filename?
For some reason, the C++ committee decided that std::fstream::open() only needed to take a character array for the filename parameter. The function doesn't accept std::strings.

To make it work, pass filename.c_str().
Topic archived. No new replies allowed.