c++ - Pass a reference to std::ifstream as parameter -


i'm trying write function ifstream& argument.

void word_transform(ifstream & infile) {     infile("content.txt");     //etc } 

which gave me error:

type 'ifstream' (aka 'basic_ifstream ') not provide call operator.

can please me what's wrong?

call operator function operator()( params ) allowing use syntax myobject( params ).

so, when write infile(...), trying call operator.

what trying open file, use open method:

void word_transform(ifstream & infile) {     infile.open("content.txt",std::ios_base::in);     if ( infile.is_open() )         infile << "hello";     infile.close(); } 

but, commented, not make sense pass infile reference such function. may consider:

void word_transform(istream& infile) {     infile << "hello"; }  int main() {     ifstream infile;     infile.open("content.txt",std::ios_base::in);     if ( infile.is_open() )         word_transform( infile );     infile.close();     return 0; } 

or:

void word_transform() {     ifstream infile;     infile.open("content.txt",std::ios_base::in);     if ( infile.is_open() )         infile << "hello";     infile.close(); }  int main() {     word_transform();     return 0; } 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -