我发现此代码似乎运行良好 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 *参数的第二个无效。为什么?
答案 0 :(得分:0)
您需要的只是一个const char *参数。
const char* s = "123abcd";