I am running into a problem with the accessing a binary file via the input file stream class (ifstream).
My approach starts with the following calling function:
void ReadFile(vector<string>& argv, ostream& oss){
string FileName = argv.at(2) + "INPUT" ;
ifstream BinFile ;
OpenBinaryFile(FileName, BinFile) ;
return ;
}
The called function looks like this:
void OpenBinaryFile(string& FileName, ifstream& BinFile){
using namespace std ;
BinFile(FileName.c_str(),ifstream::binary | ifstream::in) ;
}
When I try to compile this simple scheme using gcc version 4.9.2 I get the following error:
error: no match for call to ‘(std::ifstream {aka std::basic_ifstream<char>}) (const char*, std::_Ios_Openmode)’
BinFile(FileName.c_str(),ifstream::binary | ifstream::in) ;
^
I've tried to get the caret ("^") placed exactly where the compiler did.
What's going on here? I am baffled.
Thanks!
There are two ways of opening a stream.
During construction, in a declaration:
After construction, using the
std::ifstream::open
function:In your question you are attempting to mix the two. This results in an attempt to call the non-existent "function call operator"
operator()
on the objectBinFile
.