How do I read a text file from the second line using fstream?

Tal picture Tal · Oct 2, 2008 · Viewed 81.3k times · Source

How can I make my std::fstream object start reading a text file from the second line?

Answer

Doug T. picture Doug T. · Oct 2, 2008

Use getline() to read the first line, then begin reading the rest of the stream.

ifstream stream("filename.txt");
string dummyLine;
getline(stream, dummyLine);
// Begin reading your stream here
while (stream)
   ...

(Changed to std::getline (thanks dalle.myopenid.com))