Q:

Opening file to read in C++, issue with filename string

I'm opening a file to read in C++ (Linux, Debian).
ifstream input ("readme");

The above works, but when I try:
string filename = "readme";
ifstream input (filename);

I get a page load of errors starting with error: no matching function for call to...
Why doesn't this work and how can I use a string variable as file name input?

A:

You can use :
string filename = "readme";
/* Convert filename to C string of type const char* 
 (null terminated) using c_str method
*/
ifstream input (filename.c_str()); 

Or use C++11 flag
-std=c++11 or -std=c++0x
Ref: c_str

