-1
我正在使用正则表达式尝试在一行代码(4个整数)中查找一年。我有一个错误编译在这一行,如果他们发现我想要返回他们作为整数的四个字符。类型smatch没有可行的重载运算符
if(regex_search(names,match,expr)){
return stoi(match[index]);
}
该索引似乎是问题,这是一个无符号索引,作为函数查找年的参数。感谢您的帮助,让我知道您是否需要更多信息。
这里是所有的代码在你的代码
#include <iostream>
#include <fstream>
#include <string>
#include <regex>
using namespace std;
int find_year(string& names, unsigned index = 0);
int main(){
ifstream oldretire;
string names;
oldretire.open("oldretirement.txt");
getline(oldretire, names);
int year = find_year(names);
cout << year;
}
int find_year(string& names){
smatch match;
regex expr("[0-9]{4}");
if(regex_search(names,match,expr)){
return stoi(match[index]);
}
else
cout << "No matching arguement";
}
发布所有代码。 –
好吧,我发布了所有 – jchud13
为什么如果你只需要匹配值就使用'index'?尝试'stoi(match.str())' –