原始.log文件:
修改后的.log文件:
简单来说,就是我把所有重复比较以及相同图像进行比较的图像对信息给删除了,保留不重复的比较信息以及非同一张图像保留的情况,具体代码在下面给出,涉及了基本的文件读写操作,以及string字符串比较大小的操作!!!!!!
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
//如果s1大就返回1,相等返回-1,s2大返回0,此方法仅适用于该命名情况下的大小比较,具体格式见文件格式
int my_compare(string s1, string s2);
int main()
{
ifstream in("D:\\Whhuo-Siamese-pytorch-master\\Siamese-pytorch\\recode.log");
ofstream out("D:\\Whhuo-Siamese-pytorch-master\\Siamese-pytorch\\new.log");
if (!in.is_open() || !out.is_open())
{
cout << "没有该文件" << endl;
return -1;//异常退出
}
string s = "";
while (getline(in, s))
{
if (s.size() == 0) continue;
stringstream ss(s);
string temp1;//根据前面字符串判断,然后删除该行
string temp2;
string temp3;
ss >> temp1 >> temp2 >> temp3;
//cout << temp1 << " " << temp3 << endl;
if (1 == my_compare(temp1, temp3) || -1 == my_compare(temp1, temp3))
{
continue;
}
else
{
out << s << endl;
}
}
in.close();
out.close();
system("pause");
return 0;
}
//如果s1大就返回1,相等返回-1,s2大返回0
int my_compare(string s1, string s2)
{
if (s1.size() == s2.size())
{
if (s1 > s2)
{
//cout << "s1大" << endl;
return 1;
}
else if (s1 < s2)
{
//cout << "s2大" << endl;
return 0;
}
//cout << "两者相等" << endl;
return -1;
}
else if (s1.size() > s2.size())
{
//cout << "因为s1的尺寸大,所以s1大,至少在这个场合是这样" << endl;
return 1;
}
//cout << "因为s2的尺寸大,所以s2大,至少在这个场合是这样" << endl;
return 0;
}