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++<<'\n';
}