Wednesday 11 December 2013

Source code: File in C++ [ skeleton code ]

#include<iostream>  //to add to the or read from the file
#include<fstream> //for file input and output purpose
using namespace std;
int main()
{
    ofstream flobj; //start opening a file with a file object nane
flobj.open("file.txt");

if(flobj.is_open())
{
flobj<<"victory shall be mine.";
cout <<"attaboy\n\n";
}
else
{
cout <<"this aint your day pal\n\n";
}

flobj.close(); //closing the file( good practice)
}

No comments:

Post a Comment