Input
Output
#include <fstream> #include <iostream> using namespace std; int main () { char ch[50]; ofstream f1; // open a file in write mode. f1.open("test.txt"); cout << "Writing to the file" << endl; cout << "Enter the employee name: " << "Sundarrajan" << endl; //cin.getline(ch, 50); f1 << ch << endl; // write input data into the file. cout << "Enter your age: " << "60" << endl; //cin >> ch; cin.ignore(); f1 << ch << endl; // again write input data into the file. f1.close();// close the file. // open a file in read mode. ifstream f2; string output; f2.open("test.txt"); cout << "Reading from a text file: " ; while (getline (f2,output)) { cout << output << endl; } f2.close(); return 0; }