I have a large string which can be 50-200 MB. I want to iterate over the lines in the string. Most of the solutions I searched use std::getline and some of them required Boost library. I am not using them because, for example, they require me to copy the string to create a stringstream.
Do I really need to use them? Why should I not simply use std::string
's find
to search for \\n
and read sub-strings? Is it a bad solution?
std::getline
or Boost.string.find()
. Or, you could read the string from its source and build a list of substrings as you find the separators.Also, you can use std::string_view in C++17. Therefore, you can put your entire input into one string then create cheap substring objects that reference the original string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.