#include #include #include #include using namespace std; int main() { // Reading one word at a time with << // Then switching to getline // \n = LF = line feed must be accounted for int char_count; string cppstr; ifstream myfile("files-many.txt"); if (myfile.fail()) { cout << "Fail bit set" << endl; return 1; } // Read line 1 myfile >> cppstr; cout << "\"" << cppstr << "\"" << " is first" << endl; myfile >> cppstr; cout << "\"" << cppstr << "\"" << " is second" << endl; myfile >> cppstr; cout << "\"" << cppstr << "\"" << " is third" << endl << endl; // Read LF for line 1 getline(myfile, cppstr); cout << "\"" << cppstr << "\"" << " has just been read" << endl; // Read line 2 getline(myfile, cppstr); cout << "\"" << cppstr << "\"" << " has just been read" << endl; // Read line 3 getline(myfile, cppstr); cout << "\"" << cppstr << "\"" << " has just been read" << endl; // We are not at EOF yet if (myfile.eof()) { cout << "end of file" << endl; } myfile.close(); myfile.clear(); return 0; }