Read a string line by line using c++

前端 未结 5 1612
不思量自难忘°
不思量自难忘° 2020-12-15 03:30

I have a std::string with multiple lines and I need to read it line by line. Please show me how to do it with a small example.

Ex: I have a string

5条回答
  •  [愿得一人]
    2020-12-15 04:08

    There are several ways to do that.

    You can use std::string::find in a loop for '\n' characters and substr() between the positions.

    You can use std::istringstream and std::getline( istr, line ) (Probably the easiest)

    You can use boost::tokenize

提交回复
热议问题