string fname = "a.txt"; string buf; fstream fp(fname ); while (!fp1.eof() && fp1.peek() != EOF){ getline(fp1, buf);// read one line } fp.close();