原因是自己写的程序保存文件时没有按照标准pascal的格式,今天写了个小程序,转换了其文本格式,问题得以解决,具体解决办法的code如下:
//xml格式转换功能函数
void xmlFormatForTab()
{
vector<string> filesOfXmls;
string pth_xml;
pth_xml = "M:\\car\\";
getFiles(pth_xml, filesOfXmls);
int sizeOfXmls = filesOfXmls.size();
cout << sizeOfXmls << endl;
ifstream ifs_read_xml;
fstream fs_write_xml;
for (int l = 0; l < sizeOfXmls; l++)
{
ifs_read_xml.open(filesOfXmls[l].c_str(), ios::in);
string filesOfxml = filesOfXmls[l];
const char pth_tmp[17] = "\\carFinal";
filesOfxml.insert(6, pth_tmp);
filesOfXmls[l].erase(7,1);
filesOfxml.erase(15,1);
string new_pth_xml = filesOfxml;
fs_write_xml.open(new_pth_xml, ios::out);
for (int line = 0; line < 33; line++)
{
if (line == 0)
{
continue;
}
else
{
char p[100] = { 0 };
int pos = 0;
string p_tmp;
ifs_read_xml.getline(p, 100, '\n');
cout << strlen(p) << endl;
cout << line << endl;
for (int index = 0; index < strlen(p); index++)
{
if (p[index] == '<')
{
pos = index-1;
break;
}
else
{
continue;
}
}
cout << pos << endl;
if (line == 3 || line == 4 || line == 5 || line == 10 || line == 11 || line == 14 || line == 15 || line == 19 || line == 20 || line == 21 || line == 32)
{
p_tmp = p;
p_tmp.erase(0, 2);
cout << p_tmp << endl;
p_tmp.insert(0, 1, '\t');
fs_write_xml.write(p_tmp.c_str(), strlen(p_tmp.c_str()));
fs_write_xml.write("\n", 1);
}
else if (line == 6 || line == 7 || line == 8 || line == 9 || line == 12 || line == 13 || line == 16 || line == 17 || line == 18 || line == 22 || line == 23 || line == 24 || line == 25 || line == 26 || line == 31)
{
p_tmp = p;
p_tmp.erase(0, 4);
cout << p_tmp << endl;
p_tmp.insert(0, 2, '\t\t');
fs_write_xml.write(p_tmp.c_str(), strlen(p_tmp.c_str()));
fs_write_xml.write("\n", 1);
}
else if (line == 2 || line > 32)
{
p_tmp.erase(0, 1);
p_tmp = p;
cout << p_tmp << endl;
fs_write_xml.write(p_tmp.c_str(), strlen(p_tmp.c_str()));
fs_write_xml.write("\n", 1);
}
else if (line==27||line==28||line==29||line==30)
{
p_tmp = p;
p_tmp.erase(0, 6);
cout << p_tmp << endl;
p_tmp.insert(0, 3, '\t\t\t');
fs_write_xml.write(p_tmp.c_str(), strlen(p_tmp.c_str()));
fs_write_xml.write("\n", 1);
}
else
{
cout << "skip\n" << endl;
}
}
}
fs_write_xml.write("</annotation>", 13);
fs_write_xml.close();
ifs_read_xml.close();
}
}
写的比较啰嗦,也不具有通用性,不过能解决自己的问题,也OK了!