C++ examples for File Stream:stream
Returning True When ostream Cannot Create a File
#include <iostream> #include <fstream> using namespace std; int main() // w w w .j a v a2 s. c o m { ofstream outfile("/MyFile.txt"); if (outfile.fail()) { cout << "Couldn't open the file!" << endl; return 0; } outfile << "Hi" << endl; outfile.close(); return 0; }