regex is not a member of std—regex 不是std 的成员

std::regex is part of the C++11 STL, and it's not clear which compiler directives are used by this OJ, it could be they just didn't put the -std=c++11 part.


http://www.cnblogs.com/beita/p/4759425.html

1、这几天,使用c++的regex库写字符串处理程序,编译时出现:

ary support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the
  ^
regex_std1.cpp: In function ‘int main(int, char**)’:
regex_std1.cpp:8:2: error: ‘regex’ is not a member of ‘std’
……

根据提示使用:

g++ regex_std1.cpp -std=c++0x或

g++ regex_std1.cpp -std=c++11或

g++ regex_std1.cpp -std=gnu++11

进行编译可通过。

2、regex_match与regex_search的一个区别

两者的匹配要求是不一样的,前者需要整个字符串符合正则表达式才返回真,而后者只需要字符串的一部分符合正则表达式即可返回真,

所以注意下面这个匹配,将返回假:

std::regex reg("wang");

std::string s("hello, wang");

regex_match(s, reg); // 返回flase

而,下面返回真:

std::regex reg("wang");

std::string s("hello, wang");

std::smatch sm;  //match_results类, 可选参数

regex_search(s, sm , reg); // 返回真

详情可见:http://blog.csdn.net/helonsy/article/details/6800790

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(77) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
原文地址:https://www.cnblogs.com/ztguang/p/12649306.html