How to make "getline" from std :: string?

I have a problem. I download the whole file and then get it to get some information. However, the map format can contain 0 or 20 β€œlines” of information. I need to know how to getline via std :: string. There is a function (source stream, end line, decimal), but I need (source line, target line, decimal). Searching in streams is not possible in C ++ (only using many temp lines and extracting and pasting many times, this is unclear, and I don't want to do it in a dirty way). So I want to know how to getline from std :: string.

Thans

+8
c ++ string stream getline
source share
1 answer

It seems you want std::istringstream , which is in the <sstream> header:

 std::string some_string = "..."; std::istringstream iss(some_string); std::string line; while (std::getline(iss, line)) { // Do something with `line` } 
+17
source share

All Articles