作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在测试Stroustrup C++ 4th Ed Page 1069中的示例,其中可能未列出勘误表here。有谁知道应该如何修改此代码才能正确打印以下输出?这本书声称这应该是输出,但是我的测试什么也不输出(没有匹配项)。
#include <regex>
#include <iostream>
using namespace std;
int main()
{
string input {"aa::bb cc::dd ee::ff"};
regex pat {R"((\w+)([[:punct:]]+)(\w+)\s∗)"};
sregex_token_iterator end {};
for (sregex_token_iterator p {input.begin(),input.end(),pat,{1,3}};
p!=end; ++p)
cout << *p << '\n';
return 0;
}
书本声明输出应为:
aa
bb
cc
dd
ee
ff
汇编:
clang++ -Wall -std=c++11 -pedantic test248.cc && ./a.out
Compilation finished at Wed Aug 5 20:09:52
最佳答案
regex pat {R"((\w+)([[:punct:]]+)(\w+)\s∗)"};
最后的“星号”不是实际的
*
星号,而是Asterisk Operator Unicode字符
U+2217。将其替换为
*
和代码
will work。
关于c++ - sregex_token_iterator:Stroustrup示例是否有勘误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63275170/
我是一名优秀的程序员,十分优秀!