下面的代码怎么了?为何for换内部不执行?
#include <string>
#include <iostream>
#include <regex>
#include <fstream>
using namespace std;
bool valid(const smatch &);
int main()
{
cout << "good" << endl;
string pattern("(\\()?(\\d{3})(\\))?([-.]?|[[:blank:]]*)(\\d{3})([[:blank:]]* | [.-]?)(\\d{4})");
regex r(pattern);
smatch results;
string line;
ifstream in("data.txt");
while(getline(in,line))
{
cout << "line:" << line << endl;
for(sregex_iterator it(line.begin(),line.end(),r),end;it != end; ++ it)
{
cout << "for"<< endl;
if(valid(*it))
{
cout << it -> str() << endl;
}
else
{cout << it->str() << " is not legal." << endl;}
}
}
return 0;
}
bool valid(const smatch &s)
{
if(s[1].matched)
{
return s[3].matched && (!s[4].matched || s[4].str() == " ");
}
else
{
return s[3].matched == 0 && (s[4].str() == s[6].str());
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)