抛出“std::regex_error”实例后调用终止

use*_*858 5 c++ ubuntu g++

我只是想匹配“{”。但不知道为什么会出现这个错误:

terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu 上使用 g++ 版本 4.6.3 进行编译

g++   -std=c++0x   a.c
Run Code Online (Sandbox Code Playgroud)

程序

#include<iostream>
#include<regex>


using namespace std;

main(int argc,char**argv){

        if (regex_match("{1}" , std::regex ("[{]"))) {
                cout<<"Hello World"<<endl;
        }

}
Run Code Online (Sandbox Code Playgroud)

我还检查了ECMAScript详细信息,这个正则表达式应该匹配。当我使用 like 时它也不匹配:std::regex ("\\{"))

我怎么了?

mar*_*inj 6

至少需要gcc 4.9才能使正则表达式与 gcc 一起使用,一旦您将添加 4.9 版本.*以使其与字符串的其余部分匹配:

if (regex_match("{1}" , std::regex ("[{].*"))) {
                                        ^^
Run Code Online (Sandbox Code Playgroud)

http://coliru.stacked-crooked.com/a/99e405e66906804d