c++ - 如何从 VC++ 2010 中的 std::regex 获取带有模式的字符串

标签 c++ regex c++11 visual-c++-2010

我可以从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 of charT 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/

相关文章:

c++ - 虚幻引擎 : Accessing blueprint instance data of dynamically spawned actor

javascript - 仅当不被加号包围时才使用 RegEx 拆分字符串以匹配&符号

c++ - 模板类中模板方法的友元,在模板类中

C++ - thread_local 变量存储在哪里?

c++ - if 的感觉——这怎么可能起作用

c++ - 如何检测 USB 驱动程序启用/禁用

C++ stringstream使字符串指针无效

java - 正则表达式查找行中的合并部分

JavaScript RegExp 用于电话号码验证,需要在数字之间允许连字符和空格

c++ - 与自定义对象一起使用 accumulate