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


Question

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

1
17
9/2/2016 7:53:59 PM

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))

27
10/2/2008 8:21:29 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon