2
bool validateCurrencyLine(string line){
cout << "TESTING LINE : " << line << endl;
string pattern = "[ ]*([A-Z]{3}) ([0-9]+)([ ]*|,[0-9]+[ ]*)";
boost::regex expr{pattern};
return boost::regex_match(line,expr);
}
int main()
{
string line;
while(getline(cin,line)){
cout << validateCurrencyLine(line) << endl;
}
return 0;
}
test
文件的内容如下:不同结果
IDK 3453443
现在,当我使用./a.out < test
结果是启动程序
TESTING LINE : IDK 3453443
0
TESTING LINE :
0
我的假设是,第二条线是印刷,因为testfile的第一行实际上是
IDK 3453443 +进入
我是正确)
但真正的问题是,当我象这样开始:./a.out
并输入“IDK 3453443”,然后按回车。结果是:
TESTING LINE : IDK 3453443
1
这两个结果有什么不同?
你确定在文件中的\ n之前没有'\ r'吗?这可能是罪魁祸首...尝试'string pattern =“[] *([AZ] {3})([0-9] +)([] * |,[0-9] + \\ s *) “'。或'regex_search'而不是'regex_match'。 –
不幸的是,新模式仍然没有工作@stribizhev – user3142434