Well ... first please see this example using C++ ifstream:
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
{
cout << "Please give a file name." << endl;
return 1;
}
ifstream in(argv[1]);
if (in)
{
cout << "Success!" << endl;
in.close();
}
if (!in)
{
cout << "Failure!" << endl;
return 2;
}
return 0;
}
My question is how does ifstream object behave like a bool value in above code?
I want to write my own class. And I wish it's objects would behave in the same way.
Can you please tell me how can I write such a class?