I have this function:
void check_open (ifstream& file)
{
if (not file.is_open())
{
cout << "Error." << endl;
exit(1);
}
}
but I can only pass ifstream arguments, how can i make it to accept also ofstream arguments?
As long as the stream has an is_open()
method, the function below works just fine (fstream
, ifstream
, ofstream
, and the variants of them with different character types).
template<typename stream_type>
void check_open (const stream_type& file)
{
if (not file.is_open())
{
cout << "Error." << endl;
exit(1);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments