C++ ofstream fail to create file

Description

C++ ofstream fail to create file

#include <iostream> 
#include <fstream> 

using namespace std; 

int main() /*from  w  w w  .ja v  a 2 s  .  c om*/
{ 
    ofstream outfile("/MyFile.txt"); 
    if (outfile.fail()) { 
        cout << "Couldn't open the file!" << endl; 
        return 0; 
    } 
    outfile << "Hi" << endl; 
    outfile.close(); 

    return 0; 
}



PreviousNext

Related