chellrose
April 28th, 2013, 07:41 AM
I'm including iostream, fstream, string, and cstdlib headers. In my program, if I have
ofstream os;
string file = "infoFile.txt";
os.open(file, ios::app);
upon compilation I see the error
NoteOrganizer.cpp:28:31: error: no matching function for call to ‘std::basic_ofstream<char>::open(std::string&, const openmode&)’
NoteOrganizer.cpp:28:31: note: candidate is:
/usr/include/c++/4.6/fstream:702:7: note: void std::basic_ofstream<_CharT, _Traits>::open(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.6/fstream:702:7: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const char*’
but if I instead do
os.open("infoFile.txt", ios::app);
it compiles and runs just fine. I've used strings as file names countless times before, though, with no trouble at all. What is going wrong?
(BTW: I'm using g++)
Thanks! :)
ofstream os;
string file = "infoFile.txt";
os.open(file, ios::app);
upon compilation I see the error
NoteOrganizer.cpp:28:31: error: no matching function for call to ‘std::basic_ofstream<char>::open(std::string&, const openmode&)’
NoteOrganizer.cpp:28:31: note: candidate is:
/usr/include/c++/4.6/fstream:702:7: note: void std::basic_ofstream<_CharT, _Traits>::open(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.6/fstream:702:7: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const char*’
but if I instead do
os.open("infoFile.txt", ios::app);
it compiles and runs just fine. I've used strings as file names countless times before, though, with no trouble at all. What is going wrong?
(BTW: I'm using g++)
Thanks! :)