0

Is there any ways to start parsing from 2nd line of txt file using seekg() function? If the 1st line is terminated by "\n"

Or any other recommended solutions for straight parsing 2nd line of txt file.

  • 1
    Sure, do you know *exactly* how long the first line of text is? – tadman Oct 30 '22 at 16:12
  • Are you aware of [std::getline](https://en.cppreference.com/w/cpp/string/basic_string/getline)? – Nathan Pierson Oct 30 '22 at 16:14
  • std::getline on a std::ifstream into a std::string and check its content. Probably much easier then using seekg(). https://www.learncpp.com/cpp-tutorial/basic-file-io/ – Pepijn Kramer Oct 30 '22 at 16:14
  • Because i'm using a 'while loop' to parse my whole file. And i wanted it to start parsing from second line. – Patrick Lee Oct 30 '22 at 16:15
  • 2
    just read the first line with std::getline, and then read the second line and do what you want with it. you can't really use the seek functions on text files unless they are rigidly fixed-formatted – Neil Butterworth Oct 30 '22 at 17:28
  • https://stackoverflow.com/questions/2581794/skip-lines-in-stdistream – Lance Oct 30 '22 at 18:39

0 Answers0