C++ ifstream error using string as opening file path.
Change
ifstream file(filename);
to
ifstream file(filename.c_str());
Because the constructor for an ifstream
takes a const char*
, not a string
pre-C++11.
The ifstream
constructor expects a const char*
, so you need to do ifstream file(filename.c_str());
to make it work.
in c++-11 it can also be an std::string. So (installing c++-11 and) changing the dialect of you project to c++-11 could also fix the problem.