您的位置:首页 > 编程语言 > C语言/C++

c++ 使用正则表达式分割字符串

2011-09-18 16:53 525 查看
#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++<<'\n';

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: