regex_search在cppreference中抛出错误 [英] regex_search in cppreference throw error

查看:178
本文介绍了regex_search在cppreference中抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cppreference网站中执行示例程序,并抛出错误。怎么可能?请帮助



我也尝试在我的4.8.1 GCC编译器,它也抛出错误。



输出:


regex_error'

  what():regex_error 




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

int main()
{
std :: string lines [] = {Roses are#ff0000,
violets are#0000ff,
我的所有基地都属于你};

std :: regex color_regex(#([a-f0-9] {2})
([a-f0-9] {2})
([a-f0-9] {2}));

for(const auto& line:lines){
std :: cout<线<< :
<< std :: regex_search(line,color_regex)<< '\\\
';
}

std :: smatch color_match;
for(const auto& line:lines){
std :: regex_search(line,color_match,color_regex);
std :: cout<< matches for'<<线<< '\\\
;
for(size_t i = 0; i< color_match.size(); ++ i){
std :: ssub_match sub_match = color_match [i];
std :: string sub_match_str = sub_match.str();
std :: cout<< i<< :<< sub_match_str<< '\\\
';
}
}
}


解决方案>

在GCC 4.8.1中,完全支持C ++ 11核心语言,但是与Clang不同,GCC不完全支持C ++ 11标准库。
libstdc ++实现状态页,std :: regex尚未完全实现。


I ran the sample program in cppreference website and throw an error. How can that be? please help

I also try on my 4.8.1 GCC compiler and it throw error either.

Output:

terminate called after throwing an instance of 'std::regex_error'

  what():  regex_error

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

int main()
{
    std::string lines[] = {"Roses are #ff0000",
                           "violets are #0000ff",
                           "all of my base are belong to you"};

    std::regex color_regex("#([a-f0-9]{2})"
                            "([a-f0-9]{2})"
                            "([a-f0-9]{2})");

    for (const auto &line : lines) {
        std::cout << line << ": " 
                  << std::regex_search(line, color_regex) << '\n';
    }   

    std::smatch color_match;
    for (const auto &line : lines) {
        std::regex_search(line, color_match, color_regex);
        std::cout << "matches for '" << line << "'\n";
        for (size_t i = 0; i < color_match.size(); ++i) {
            std::ssub_match sub_match = color_match[i];
            std::string sub_match_str = sub_match.str();
            std::cout << i << ": " << sub_match_str << '\n';
        }   
    }   
}

解决方案

In GCC 4.8.1, C++11 core-language is fully supported, but unlike Clang, GCC does not have full support for the C++11 Standard Library. As it can be seen on the libstdc++ Implementation Status page, std::regex are not fully implemented yet.

这篇关于regex_search在cppreference中抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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