【发布时间】:2015-11-13 21:05:56
【问题描述】:
我是 C++ 的初学者并试图找到一个正则表达式匹配,但即使 xml 文件中有 94893274123 (没有空格)它也找不到匹配项。我不太确定它是否正确读取了 xml 文件...
int main (){
string line;
ifstream infile("example.xml");
if (infile.is_open()){
ofstream outfile ("out.txt", ios_base::ate | ios_base::app);
if (outfile.is_open()){
while (getline(infile, line)){
//ID
regex idnr (".*+<ID-Number>([0-9]+)<.*");
smatch id_match;
if (regex_match (line.cbegin(), line.cend(), id_match, idnr)){
cout << "Match found \n";
}
}
//closing all files
outfile.close();
infile.close();
}
else cout << "Unable to open output file\n";
}
else cout << "Unable to open input file\n";
return 0;
}
程序运行返回 0 但仅此而已。我要做的是将xml文件分解为我需要的信息片段,稍后将其保存到变量或向量中,然后将它们重新组织到另一个文件中。
谢谢大家的回答...
【问题讨论】:
-
请阅读how to ask 并描述什么不起作用。
-
你说的不工作是什么意思?请发几个例子
-
将“它不工作”替换为 1) 示例输入,2) 对您希望程序执行的操作的描述,以及 3) 对程序实际执行操作的描述。
-
不好意思之前,发的比较着急……现在可以理解了吗?
标签: c++ regex xml string-matching