c++ - Compiler throws an exception when trying to compile code containing binary ifstream -
i running problem accessing binary file via input file stream class (ifstream).
my approach starts 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 this:
void openbinaryfile(string& filename, ifstream& binfile){ using namespace std ; binfile(filename.c_str(),ifstream::binary | ifstream::in) ; }
when try compile simple scheme using gcc version 4.9.2 following error:
error: no match call ‘(std::ifstream {aka std::basic_ifstream<char>}) (const char*, std::_ios_openmode)’ binfile(filename.c_str(),ifstream::binary | ifstream::in) ; ^
i've tried caret ("^") placed compiler did.
what's going on here? baffled.
thanks!
there 2 ways of opening stream.
during construction, in declaration:
std::ifstream binfile(filename, std::ifstream::binary | std::ifstream::in);
after construction, using
std::ifstream::open
function:std::ifstream binfile; binfile.open(filename, std::ifstream::binary | std::ifstream::in);
in question attempting mix two. results in attempt call non-existent "function call operator" operator()
on object binfile
.
Comments
Post a Comment