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.

  1. during construction, in declaration:

    std::ifstream binfile(filename, std::ifstream::binary | std::ifstream::in); 
  2. 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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -