bool TDatTransform::ReadLogFile(const char path[],int &sign,int &level,int &z,int &y)
{
char log[20];
std::ifstream in(path);
if (!in.is_open())//判断文件是否为空
{
std::cout << "no log file" << std::endl;
return false;
}
in.getline(log, 20);//每次读一行,读一行后数据流会跳到下一行
sign = std::atoi(log);
std::vector<std::string> image1;//stl容器,这个比数组好用
in.getline(log, 20);
level = std::atoi(log);
while (!in.eof())
{
in.getline(log, 20);//循环按行读取txt文本数据
image1.push_back(log);
}
if (sign == 1)//当log文件记录到level层时读取的断点
{
if (image1.size() == 1)
{
z = 0;
y = 0;
return true;
}
string temp = "";
if (image1[image1.size() - 1] == "")
temp = image1[image1.size() - 2];
else
temp = image1[image1.size() - 1];
int i = 0;
string getid = "";
for (i; i < 20; i++)
{
if (temp[i] != ' ')
getid = getid + temp[i];
else
break;
}
z = std::atoi(getid.c_str());
getid = "";
for (int j = i + 1; j < 20; j++)
if (temp[j] != '\0')
getid = getid + temp[j];
else
break;
y = std::atoi(getid.c_str());
}
else//当数据为temp层进行的操作
{
if (image1.size() == 1)
{
z = 0;
y = 0;
return true;
}
std::vector<int> image_id;
for (int i = 0; i < image1.size() - 1; i++)
{
image_id.push_back(atoi(image1[i].c_str()));
}
sort(image_id.begin(), image_id.end());
if (image_id[0] != 0)
{
z = 0;
return true;
}
for (int i = 0; i < image_id.size() - 1; i++)
{
if (i == image_id.size() - 2)
z = image_id[i];
if (image_id[i] == image_id[i + 1] - 1)
continue;
else
{
z = image_id[i];
break;
}
}
}
return true;
}