C++实现split函数

#include <string>
#include <vector>

vector<string> split(string s, string p){
    vector<string> res;
    std::string::size_type i = 0;
    std::string::size_type found = s.find(p);
    while (found != std::string::npos){
        res.push_back(s.substr(i, found - i));
        i = found + p.size();
        found = s.find(p, i);
    }
    res.push_back(s.substr(i, s.size() - i));
    return res;
}
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享