Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / C++ 使用正则表达式分割字符串

C++ 使用正则表达式分割字符串#include <iostream>
#include <string>
#include <boost/regex.hpp>int main(){
    std::string  s = "who,lives:in-a,pineapple  under the sea?";
    boost::regex re(",|:|-|\s+");
    boost::sregex_token_iterator
        p(s.begin(),s.end(),re,-1);
    boost::sregex_token_iterator end;
    while(p!=end)
    std::cout<<*p++<<" ";
}