02 Jul, 2011, JohnnyStarr wrote in the 1st comment:
Votes: 0
In gcc 4.5.2 I have this issue

lexer.cpp: In member function bool Lexer::loadFile(const std::string&):
lexer.cpp:122:20: error: no matching function for call to std::basic_ifstream<char>::basic_ifstream(const std::string&)
/usr/include/c++/4.5/fstream:455:7: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
/usr/include/c++/4.5/fstream:441:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.5/iosfwd:111:11: note: std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)


It seems that sending const string& for the file path is not working in gcc. Works fine in MS VC++.
Not really sure what to do about this. Should I convert the string to a c_str?
03 Jul, 2011, Kline wrote in the 2nd comment:
Votes: 0
I ended up using c_str for my own use of ifstream.


bool infile_init( string filename, ifstream &file )
{
file.open(filename.c_str(), ios::in);
if ( file.is_open() )
return true;

cout << "Unable to open input file [" << filename << "]. Aborting." << endl;

return false;
}
03 Jul, 2011, Kaz wrote in the 3rd comment:
Votes: 0
JohnnyStarr said:
It seems that sending const string& for the file path is not working in gcc. Works fine in MS VC++.


std::ifstream does not have a constructor that takes a std::string specified by the Standard. MSVC++ may offer it as an extension.

Quote
Not really sure what to do about this. Should I convert the string to a c_str?


Yes.
0.0/3