例如.如果我有一个像"第一个第二个第三个"的字符串,我想在一个操作中匹配每个单词,逐个输出.
我只是认为"(\ 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)
我期待着你的帮助.:)