parsing - Parse (split) a string in C++ using string delimiter (standard C++) - Stack Overflow

PHOTO EMBED

Mon Nov 14 2022 09:20:02 GMT+0000 (Coordinated Universal Time)

Saved by @leawoliu #cpp

#include <iostream>
#include <string>

int main()
{
    std::string s = "scott>=tiger";
    std::string delim = ">=";

    auto start = 0U;
    auto end = s.find(delim);
    while (end != std::string::npos)
    {
        std::cout << s.substr(start, end - start) << std::endl;
        start = end + delim.length();
        end = s.find(delim, start);
    }

    std::cout << s.substr(start, end);
}
content_copyCOPY

https://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c