C++实现类似python中的字符串split函数

void string_split(const std::string& s, std::vector<std::string>& tokens, const std:: string& delimeters){
    std::string::size_type lastPos = s.find_first_not_of(delimeters, 0);
    std::string::size_type pos = s.find_first_of(delimeters, lastPos);
    while( pos != std::string::npos || lastPos != std::string::npos){
        tokens.emplace_back(s.substr(lastPos, pos - lastPos));
        lastPos = s.find_first_not_of(delimeters, pos);
        pos = s.find_first_of(delimeters, lastPos);
    }
}
posted @ 2020-04-23 15:05  一条图图犬  阅读(316)  评论(0编辑  收藏  举报