void foo(ifstream &ifs)
{
//do something
}
int main()
{
fstream fs("a.txt", fstream::in);
foo(fs); //error, can't compile
}
The above code can't compile, seems like I can't initialize an ifstream &
with a fstream
object? What if I do it this way:
foo(static_cast<ifstream>(fs));
or
foo(dynamic_cast<ifstream>(fs));
Probably you want foo() to take istream. As indicated in the comments, this is a base type for both ifstream and fstream.
void foo( istream & is )
There is a nice reference for these classes at cplusplus.com:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With