Skip lines in std::istream

后端 未结 4 972
我在风中等你
我在风中等你 2021-01-12 03:05

I\'m using std::getline() to read lines from an std::istream-derived class, how can I move forward a few lines?

Do I have to just read and discard them?

4条回答
  •  北海茫月
    2021-01-12 03:15

    Yes use std::getline unless you know the location of the newlines.

    If for some strange reason you happen to know the location of where the newlines appear then you can use ifstream::seekg first.

    You can read in other ways such as ifstream::read but std::getline is probably the easiest and most clear solution.

提交回复
热议问题