I have a small program where i initialize a string and write to a file stream:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
std::ofstream ofs(file.c_str());
string s="Hello how are you";
if(ofs)
ofs<<s;
if(!ofs)
{
cout<<"Writing to file failed"<<endl;
}
return 0;
}
My diskspace is very less, and the statement "ofs<" fails. So I know that this is an error logically.
The statement "if(!ofs)" does not encounter the above issue, hence I am unable to know why it failed.
Please tell me, by which other options I would be able to know that "ofs< has failed.
Thanks in advance.
See Question&Answers more detail:os