I have to admmit that the
c++ compiler errors are sometimes somewhat hard to read, especially because very long type names and function prototypes. They are, however quite clear:
Code:
main.cpp: In function ‘bool fileExists(std::string)’:
main.cpp:10:31: error: no matching function for call to ‘std::basic_ifstream<char>::basic_ifstream(const string&)’
main.cpp:10:31: note: candidates are:
In file included from main.cpp:2:0:
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/fstream:460:7: note: 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/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/fstream:460:7: note: no known conversion for argument 1 from ‘const string {aka const std::basic_string<char>}’ to ‘const char*’
...
fstream has no
constructor that takes a string as an argument. It takes
const char* instead. The compiler does not know how to convert
string to
const char*.
You can do this by calling the method
string::c_str(). So,
Code:
std::ifstream infile(fileName.c_str());
should solve the problem. The same bug appears in several other places in the code. Another error is:
Code:
main.cpp:36:3: error: ‘system’ is not a member of ‘std’
main.cpp:37:9: error: ‘exit’ was not declared in this scope
These require
Anyway,
system("PAUSE"); is a non-portable windows bad habit that will not work in linux. There are many threads around that discuss this, so just search for them.
Another note:
Code:
bool fileExists(const std::string);
I would recommend to pass strings (and other large objects) by reference, rather than by value to avoid unnecessary copying.
Code:
bool fileExists(const std::string&);