13

为什么这在 g++ (Debian 4.6.3-1) 4.6.3 或 clang 版本 3.2 (trunk 159457) 中找不到匹配项

#include <iostream>
#include <string>
#include <regex>

using namespace std;

int main()
{
    string line("test");
    regex pattern("test",regex_constants::grep);
    smatch result;

    bool ret(false);
    ret = regex_search(line,result,pattern);  
    cout <<  boolalpha << ret << endl;
    cout <<  result.size() << endl;
    return 0 ;
}

输出

false
0
4

3 回答 3

15

因为<regex>尚未在 libstdc++ 中实现,如此所述(第 28 节)。

现在,请改用Boost.XpressiveBoost.Regex

于 2012-06-29T22:34:32.323 回答
3

到目前为止,您的示例运行正确:

$ ~/src/gcc/inst/bin/g++ --version
g++ (GCC) 4.9.0 20140224 (experimental)

$ uname -a
Linux ... x86_64 x86_64 x86_64 GNU/Linux

执行

$ ./83-regex.x 
true
1
于 2014-03-01T14:08:38.940 回答
2

根据this change log <regex>is supported in gcc-4.9 with libstd++-v3

http://gcc.gnu.org/gcc-4.9/changes.html

于 2014-03-27T23:08:03.757 回答