std::basic_ofstream::open
doesn't take two const char*
s. (note: your subject says ofstream
but from your comments it appears you're talking about ifstream
).
http://en.cppreference.com/w/cpp/io/basic_ifstream/open
void open( const char *filename,
ios_base::openmode mode = ios_base::in );
void open( const std::string &filename,
ios_base::openmode mode = ios_base::in ); (since C++11)
The problem is the second, not the first argument.
ifstream ifs;
ifs.open("hello", "rb" /*<-- problem, this is a const char* not flags.*/);
Instead, you need to pass it std::ios_base flags
ifstream ifs("hello", std::ios_base::in | std::ios_base::binary);
or
ifstream ifs;
ifs.open("hello", std::ios_base::in | std::ios_base::binary);
--- EDIT ---
Looking at your comments following the post (why didn't you edit the post?) you are also trying to check for 'NULL'.
In C and C++ 'NULL' is a macro which is #define
d as 0. So, checking for NULL
can check for a null pointer, but it also can test for numeric values. If you want to check if the file opened, you will need to do:
m_FileInput.open("hello", std::ios_base::in | std::ios_base::binary);
if (!m_FileInput.good()) // checks if the file opened.
And you should try to use 'nullptr' instead of 'NULL' when possible.