// Program readline.cpp demonstrates how to read a line of text from a file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string str1, str2, str3, str4; // declares 4 variables
ifstream inData; // declares input stream
ofstream outData; // declares output stream
inData.open("input.dat");
// binds program variable inData to the input file "input.dat"
outData.open("output.dat");
// binds program variable outData to the output file "output.dat"
// input 4 lines
getline(inData,str1);
getline(inData,str2);
getline(inData,str3);
getline(inData,str4);
// output 4 lines
outData << str4 << endl;
outData << str3 << endl;
outData << str2 << endl;
outData << str1 << endl; // outputs 4 lines
inData.close();
outData.close();
return 0;
}
Allan Smith John Cooper Zhang Hua Yao Ming
Copyright: Department of Computer Science, University of Regina.