#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char buffer[255];
ofstream fout("text.txt");
fout << "this is a test\n";
cout << "Enter text for the file: ";
cin.ignore(1,'\n');
cin.getline(buffer,255);
fout << buffer << "\n";
fout.close();
ifstream fin("text.txt");
cout << "Here's the contents of the file:\n";
char ch;
while (fin.get(ch))
cout << ch;
fin.close();
return 0;
}
|