c++ string split

#include <iterator>
#include <regex>
std::vector<std::string> s_split(const std::string& in, const std::string& delim) {
    std::regex re{ delim };
    // 调用 std::vector::vector (InputIterator first, InputIterator last,const allocator_type& alloc = allocator_type())
    // 构造函数,完成字符串分割
    return std::vector<std::string> {
        std::sregex_token_iterator(in.begin(), in.end(), re, -1),
            std::sregex_token_iterator()
    };
}


int main() {
    ;


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

    std::vector<std::string> res;
    res = s_split(s, delimiter);
    for (int i = 0; i < res.size(); i++)
        cout << res[i] << endl;
    
    
    system("pause");
}

 

原文链接: https://www.cnblogs.com/zle1992/p/10216565.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    c++ string split

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/287949

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 上午10:33
下一篇 2023年2月15日 上午10:35

相关推荐