Sunday, 3 March 2013

How write text in a text file using C++


Program:
#include <iostream>
#include <fstream>
#include <conio.h>

using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt"); //this is the file name.
  myfile << "Writing this to a file.\n";
  myfile.close();
  cout<<"This file saved!";
  getch();
  return 0;
}

Output:
This file saved!

[example.txt]
Writing this to a file.

Thanks for watching... comment it...

No comments:

Post a Comment