指定长度char *参数的std :: regex_search在VS2017中不起作用?

时间:2018-11-01 05:39:08

标签: c++ regex stl std

我发现此代码似乎运行良好 no matching function for call to ‘regex_search(...)'

我的代码

    char* s = "123abcd";
    std::cmatch pieces_match;
    bool b = std::regex_search(s, pieces_match, std::regex("[^0-9]")); // works well
    for (auto& sub : pieces_match)
    {
        cout << sub << endl;
    }
    b = std::regex_search(s, s+2, pieces_match, std::regex("[^0-9]")); // Error C2672   'std::regex_search': no matching overloaded function found      
    for (auto& sub : pieces_match)
    {
        cout << sub << endl;
    }

第一个regex_search运行良好。分配了长度的char *参数的第二个无效。为什么?

1 个答案:

答案 0 :(得分:0)

您需要的只是一个const char *参数。

const char* s = "123abcd";