Write To File in C++

This is tutorial for writing to file in C++.
Here is the code.

#include 

using namespace std;

int main()
{
	ofstream fw;
	fw.open("file.txt");
	fw <<"You text here!"<< endl;
	fw <<"text in other line\n..."<

We include the fstream library, it contains the ofstream and ifstream classes. They are used for writting and reading to/from files.
Then, in the main function we create an object from ofstream class, and with function open we tell the object that we will write in the file "file.txt".

This will be written in the file

You text here!
text in other line
...

Related Research:

Related Articles:

Visit us for more Programming and Technology Research.

  • Digg
  • Faves
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Reddit
  • RSS
  • Technorati
  • LinkedIn
  • Twitter
  • DZone
  • Tumblr

Speak Your Mind

*