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

PHOTO EMBED

Mon Nov 14 2022 09:19:40 GMT+0000 (Coordinated Universal Time)

Saved by @leawoliu #cpp

std::string s = "scott>=tiger>=mushroom";
std::string delimiter = ">=";

size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos) {
    token = s.substr(0, pos);
    std::cout << token << std::endl;
    s.erase(0, pos + delimiter.length());
}
std::cout << s << std::endl;
content_copyCOPY

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