#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';
}
本文展示了一个使用C++ Boost库中的Boost.Regex组件来解析和拆分复杂字符串的例子。通过定义正则表达式,该示例代码可以将包含特定分隔符(如逗号、冒号、破折号及空格)的字符串拆分为单独的词汇。
1266

被折叠的 条评论
为什么被折叠?



