C++ 对';正则表达式匹配';

C++ 对';正则表达式匹配';,c++,regex,C++,Regex,有人能告诉我为什么函数regex_match不起作用吗。调用'regex\u match'时,它总是给出一个错误,即[cquery]没有匹配函数。 我熟悉python的正则表达式库,但我正在尝试这是否适用于cpp #include <iostream> #include <string> #include <regex> using namespace std; int main () { int t; cin>>t; regex r(

有人能告诉我为什么函数regex_match不起作用吗。调用'regex\u match'时,它总是给出一个错误,即
[cquery]没有匹配函数。
我熟悉python的正则表达式库,但我正在尝试这是否适用于cpp

#include <iostream>
#include <string>
#include <regex>
using namespace std;
 
int main ()
{
  int t;
  cin>>t;
regex r("^[a-m]+$");
regex r2("^[N-Z]+$");
bool b = false;
while(t--)
{
  
  int k;
  cin>>k;
  string str;
  cin>>str;
  for(int i=0;i<k;i++)
  {
    if ( regex_match(str[i],r))
      b = true;
    else if ( regex_match(str[i],r2))
      b = true;
    else
      b = false;
  }
  if (b == true)
    cout<<"YES";
  else
    cout<<"NO";  
}
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
int t;
cin>>t;
正则表达式r(“^[a-m]+$”;
正则表达式r2(“^[N-Z]+$”;
布尔b=假;
而(t--)
{
int k;
cin>>k;
字符串str;
cin>>str;

对于(int i=0;i所以您尝试将char作为输入传递给
regex_match
我猜您想要匹配子字符串,所以为了实现这一点,您应该将行更改为:

regex_match(str.substr(i, str.size() - 1),r2)
在下面的行中,将第一个参数作为char传递,这是错误的:

regex_match(str[i],r2)

是的,现在工作很好。谢谢!