Skip lines in std::istream

后端 未结 4 998
我在风中等你
我在风中等你 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:31

    For what it's worth:

    void skip_lines(std::istream& pStream, size_t pLines)
    {
        std::string s;
        for (; pLines; --pLines)
            std::getline(pStream, s);
    }
    

提交回复
热议问题