Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6507210
  • 博文数量: 1159
  • 博客积分: 12444
  • 博客等级: 上将
  • 技术积分: 12570
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 21:34
文章分类

全部博文(1159)

文章存档

2016年(126)

2015年(350)

2014年(56)

2013年(91)

2012年(182)

2011年(193)

2010年(138)

2009年(23)

分类: Web开发

2015-11-30 22:11:08

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

阅读(2745) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~