我可以从std::regex
中获取带有正则表达式的字符串吗? ?或者如果我以后想使用它,我应该将它保存在其他地方吗?
在 boost 中你可以这样做:
boost::regex reg("pattern");
string p = reg.str();
或使用<<运算符
cout << reg;
将打印 pattern。
但在 std::regex
没有 str() 或 operator<<。我应该将字符串保存在其他地方还是找不到?
在调试器中我可以看到 std::regex
中的内容.
最佳答案
我刚刚查看了 N3225,第 28.4 节(标题 <regex>
概要),事实上,basic_regex
模板没有成员函数str
, 并且没有 operator<<
提供。
第 28.8/2 段对此提供了一点见解:
Objects of type specialization of
basic_regex
are responsible for converting the sequence ofcharT
objects to an internal representation. It is not specified what form this representation takes, nor how it is accessed by algorithms that operate on regular expressions.
我的理解是标准要求 basic_regex
可以从 const charT *
构建但不需要实现来保留这个字符串。
关于c++ - 如何从 VC++ 2010 中的 std::regex 获取带有模式的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4500928/