source file name: File4.cpp
#include <fstream.h>
#include <iostream.h>
#include<conio.h>
int main ()
{
char str[75];
ofstream fout;
fout.open("testout.txt");
clrscr();
cout <<"Writing to a text file:" << endl;
cout << "Please Enter your name: ";
cin.getline(str, 100);
fout << str << endl;
cout << "Please Enter your age: ";
cin >> str;
cin.ignore();
fout << str << endl;
fout.close();
ifstream fin;
const int N=80;
char line[N];
fin.open("testout.txt");
cout << "Reading from a text file:" << endl;
while (fin)
{
fin.getline (line,N);
cout << line << endl;
}
fin.close();
getch();
return 0;
}
output:
0 Comments
Post a Comment