Write text to a file

// Write text to a file.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#include "fstream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
       //CREATE OTUPUT OBJECT ASSOCIATED WIHT FILE
       ofstream fout(FILENAME);
       cout << "Enter your text: ";
       char str[100];
       cin >> str;
       // WRITE THE TEXT TO THE FILE
       fout << " here is youre text " << "\n";
       fout << str << "\n";
       //CLOSE FILE
       fout.close();
       ifstream fin (FILENAME);
       char ch;
       while (fin.get(ch));
       cout << ch;
       fin.close();
       system("pause");
       return 0;
}



Share on Google Plus