jjzjj

c++ - 为什么使用 "cmatch"的 C++ 正则表达式代码会引发 "smatch"异常?

我是C++正则表达式的新手,无法让它们使用字符串而不是char*。到目前为止,我看到的例子都是针对C字符串的。我的真实程序(我什至不想在这里展示)使用了子匹配,但我不能让它们工作,所以我试图修改一个非常简单的工作示例,但它也不起作用。我使用VisualStudio2010Ultimate。原始-工作-代码:constchar*first="abcd";constchar*last=first+strlen(first);std::cmatchmr;std::regexrx("abc");std::regex_constants::match_flag_typefl=std::regex

c++ - std::smatch 返回了什么,你应该如何使用它?

string“我5岁了”正则表达式"(?!am)\d"如果你去http://regexr.com/并将正则表达式应用于您将获得5的字符串。我想用std::regex得到这个结果,但我不明白如何使用匹配结果,可能regex也必须改变。std::regexexpression("(?!am)\\d");std::smatchmatch;std::stringwhat("Iam5yearsold.");if(regex_search(what,match,expression)){//???} 最佳答案 std::smatch是match