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

2014-11-24 14:06:07 · 作者: · 浏览: 3

#include
#include
#include


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';
}