相关疑难解决方法(0)

如何使用std :: regex匹配多个结果

例如.如果我有一个像"第一个第二个第三个"的字符串,我想在一个操作中匹配每个单词,逐个输出.

我只是认为"(\ b\S*\b){0,}"会起作用.但实际上并没有.

我该怎么办?

这是我的代码:

#include<iostream>
#include<string>
using namespace std;
int main()
{
    regex exp("(\\b\\S*\\b)");
    smatch res;
    string str = "first second third forth";
    regex_search(str, res, exp);
    cout << res[0] <<" "<<res[1]<<" "<<res[2]<<" "<<res[3]<< endl;
}   
Run Code Online (Sandbox Code Playgroud)

我期待着你的帮助.:)

c++ regex

19
推荐指数
6
解决办法
3万
查看次数

标签 统计

c++ ×1

regex ×1