Friday, July 31, 2009

How can i create a file while writing a program in c++?

the format of the file is not important for me at all. i just need an example c++ code.

How can i create a file while writing a program in c++?
Hello,





The fstream header is used for file manipulation.





Steps:





1. Declare an ofstream var.


2. Open a file with it.


3. Write to the file (there are a couple of ways.)


4. Close it.





#include %26lt;fstream.h%26gt;





void main


{


ofstream file;


file.open("file.txt"); //open a file


file%26lt;%26lt;"Hello file\n"%26lt;%26lt;75; //write to it


file.close(); //close it


}





You can also review this article for in depth overview of the fstream classes:





http://www.daniweb.com/forums/post31214....





Hope this Helps! Best of Luck!

garden state

No comments:

Post a Comment