123456789101112131415161718192021222324
// reading a text file #include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; ifstream myfile ("numbers.txt"); if (myfile.is_open()) { while (! myfile.eof() ) { getline (myfile,line); cout << line << endl; } myfile.close(); } else cout << "Unable to open file"; return 0; }
To one what?
123
for (int lineno = 0; getline (myfile,line) && lineno < 7; lineno++) if (lineno == 6) cout << line << endl;