Well, you have to
write your own function or you can directly use the
ios::out ios::truncHere is the link to start with:
http://en.wikipedia.org/wiki/FstreamExample:
CODE
char buffer[255];
char file[80];
cout <<"Enter filename: ";
cin >>file;
ofstream fout(file); //Open for writing
fout << "This line written directly to the file...\n";
cout << "Enter text for the file: ";
cin.ignore(1,'\n'); // eat the newline after the file name
cin.getline(buffer,255); // get the user's input
fout << buffer << "\n"; // and write it to the file
fout.close(); // close the file, ready for reopen
ifstream fin(file); // reopen for reading
cout << "\nHere's the contents of the file:\n" << endl;
char ch;
while (fin.get(ch))
cout << ch;
cout << "\n***End of file contents.***\n";
fin.close();
cout <<"\nErase what is written" << endl;
system("pause");
//file is now empty due to ios::trunc
fin.open(file, ios::out | ios::trunc);
fin.close();