call operator is a function like operator()( params )
allowing to use the syntax myObject( params )
.
So, when you write infile(...)
, you are trying to us a call operator.
What you are trying to do is to open a file, use the open
method:
void word_transform(ifstream & infile)
{
infile.open("content.txt",std::ios_base::in);
if ( infile.is_open() )
infile << "hello";
infile.close();
}
But, as commented, it does not really make sense to pass infile reference to such a function. You 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;
}