// This program uses the file stream object's getline() member // function to read a line of information from the file. #include #include //#include using namespace std; int main() { // Variables needed for file input. const int LENGTH = 81; fstream nameFile; char input[LENGTH]; //using C-string // string input; //using string object // Open the file. nameFile.open("murphy.txt", ios::in); if (!nameFile) { cout << "File open error!" << endl; return 0; } // Read the file one line at at time. // while (getline(nameFile,input)) //using getline() for string object // while (nameFile >> input) //not using getline() while (nameFile.getline(input,LENGTH)) //using getline() { cout << input << endl; } // Close the file. nameFile.close(); return 0; }