没有与c ++ 11正则表达式匹配 [英] No matches with c++11 regex

查看:104
本文介绍了没有与c ++ 11正则表达式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在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()
{
字符串(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


解决方案>

因为< regex> 在libstdc ++中尚未实现,如此处(§28)。



现在,使用 Boost.Xpressive Boost.Regex


Why does this find no matches in g++ (Debian 4.6.3-1) 4.6.3 or clang version 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 ;
}

output

false
0

解决方案

Because <regex> is not yet implemented in libstdc++, as documented here (§28).

For now, use Boost.Xpressive or Boost.Regex instead.

这篇关于没有与c ++ 11正则表达式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆