12345678910111213141516171819202122232425
#include <iostream> #include <cstdlib> #include <string> #include <fstream> #include <iomanip> using namespace std; int main() { string line; ifstream myfile ("a.txt"); if(myfile.is_open()) { for (int lineno = 1; getline (myfile,line) && lineno < 4; lineno++) if (lineno == 2)//for 2nd line cout << line << endl; myfile.close(); } else cout << "Unable to open file"; return 0; }