Compilation results in an error when trying to compile code containing binary ifstream

EmilioW

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!

Lightness Races in Orbit

There are two ways of opening a stream.

  1. During construction, in a declaration:

    std::ifstream BinFile(filename, std::ifstream::binary | std::ifstream::in);
    
  2. After construction, using the std::ifstream::open function:

    std::ifstream BinFile;
    BinFile.open(filename, std::ifstream::binary | std::ifstream::in);
    

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 object BinFile.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error when trying to compile SASS code

"Incomplete type"-error when trying to open ifstream

Make Error 127 when running trying to compile code

Codenameone compilation error trying to compile for IOS (debug) with camera error

Compilation error when trying to combine hamcrest matchers

Compilation error when trying to use vector<ostringstream>

Compilation error when trying to initialize vector of structs

compilation error when trying to create a new array

Illegal Character when trying to compile java code

Compile error when trying to use increment operator

Namespace not found error when trying to compile

Compile error when trying to run make

Compile error when trying to install qjournalctl

Why do I get the error "cannot find -lcurl" when trying to compile example code?

Error when trying to convert binary to decimal (no output)

I get the error message "non-numeric argument to binary operator" when trying to run code

ComboBox trying to set selected item results in Compile error

Compilation error when trying to access an attribute from a local class method

Compilation error when trying to access the structure member with operator(->)

Compilation error when trying to find_if an unique_ptr in a vector

Compilation error when trying to reference a CloudBlockBlob in blobstorage triggered function

Compilation error when trying to use topics with EasyNetQ in F#

I got compilation error when trying to build the example codes

Compilation error when trying to remove adjacent duplicates from a template typelist

How can I not make the BINARY file when I compile the code?

syntax error when using ifstream

boost::spirit -- compiler error trying to compile most simple code

Compile Error: Invalid Outside Procedure on code trying to ping multiple servers

gcc doesn't do anything when trying to compile a code