std::vector<std::string> split(std::string s, std::string delimiter)
{
    std::vector<std::string> tokens;
    size_t pos = 0;
    std::string token;
    while ((pos = s.find(delimiter)) != std::string::npos) {
        token = s.substr(0, pos);
        tokens.push_back(token);
        s.erase(0, pos + delimiter.length());
    }
    if(int(s.length()) > 0)
    {
        tokens.push_back(s);
    }
    return tokens;
}

其他参考:
https://zhuanlan.zhihu.com/p/56163976
How to split a string in C++:
https://www.fluentcpp.com/2017/04/21/how-to-split-a-string-in-c/

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐