How to do "getline" from a std::string?

c++, getline, stream, string

Solution

You seem to want `std::istringstream`, which is in the header `<sstream>`:

std::string some_string = "...";

std::istringstream iss(some_string);

std::string line;
while (std::getline(iss, line))
{
    // Do something with `line`
}

Problem

I have a problem. I load the whole file and then getline through it to get some info. However in the map format there may be 0 or 20 "lines" with the info. I need to know how to getline through std::string. There is a function (source stream, destination string, decimal) but I need (source string, destination string, decimal). Searching in streams isn't possible in C++ (only using many temp string and extracting and inserting many times, it's unclear and I don't want to do it that messy way). So I want to know how to getline from a std::string. Thans

Original source