我正在尝试编写一个程序,该程序要读取由 4 列组成的文本文件(时间戳、登录/注销、正在注销/登录的内容、用户注销)
前任
15:47:10 OUT: "RS5K_700.EXE" SYSTEM@ALNWSPCNTRCTR1
15:47:10 IN: "RS5K_700.EXE" SYSTEM@ALNWSPCNTRCTR1
16:07:48 OUT: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
16:10:15 OUT: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
16:11:28 IN: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
16:46:34 IN: "RS500.EXE" mlulchak@alnsvpmillterm
17:01:49 OUT: "RS500.EXE" mlulchak@alnsvpmillterm
17:49:32 IN: "RS500.EXE" mlulchak@alnsvpmillterm
9:30:28 OUT: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
15:39:32 OUT: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
15:40:10 OUT: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
15:40:31 OUT: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
0:10:59 IN: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
1:28:20 IN: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
1:28:38 IN: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
1:28:41 IN: "RS5K_700.EXE" CONHorodeski@ALNWSPCNTRCTR1
我希望这个程序对列表进行排序,只写没有重新登录的行(即,如果退出,列表中应该有以后登录。列表是有序的,但时间如此,所以不用担心。)
这是我到目前为止所拥有的:
#include <iostream>
#include<fstream>
#include <string>
using namespace std;
int main()
{
ifstream inFile;
string array[2000][4];
int count, i, j, h;
inFile.open("test.rtf");
if(!inFile){
cout << "Unable to open file" << endl;
exit(1);
}
i=0;
while(!inFile.eof()) {
inFile>> array[i][0] >>array[i][1] >>array[i][2] >>array[i][3];
i++;
}
inFile.close();
j=0;
h=i;
while(j<i-1)
{
cout << j;
count=j+1;
if (array[j][1]== "OUT:")
{
while(count < i)
{
if(array[count][1]=="IN:" && array[count][2]==array[j][2] && array[count][3]==array[j][3])
{
for (int k = count; k < i; k++)
{
array[k][0] = array[k+1][0];
array[k][1] = array[k+1][1];
array[k][2] = array[k+1][2];
array[k][3] = array[k+1][3];
}
array[i-1][0] = " ";
array[i-1][1] = " ";
array[i-1][2] = " ";
array[i-1][3] = " ";
i--;
for (int k = j; k < i; k++){
array[k][0] = array[k+1][0];
array[k][1] = array[k+1][1];
array[k][2] = array[k+1][2];
array[k][3] = array[k+1][3];
}
array[i-1][0] = " ";
array[i-1][1] = " ";
array[i-1][2] = " ";
array[i-1][3] = " ";
i--;
count=i;
}
else if (array[j][1]== "IN:")
{
for (int k = j; k < i; k++)
{
array[k][0] = array[k+1][0];
array[k][1] = array[k+1][1];
array[k][2] = array[k+1][2];
array[k][3] = array[k+1][3];
}
array[i-1][0] = " ";
array[i-1][1] = " ";
array[i-1][2] = " ";
array[i-1][3] = " ";
j++;
i--;
}
else if (count=i)
{
j++;
}
else
{
count++;
}
}
}
else if (array[j][1]== "IN:")
{
for (int k = j; k < i; k++)
{
array[k][0] = array[k+1][0];
array[k][1] = array[k+1][1];
array[k][2] = array[k+1][2];
array[k][3] = array[k+1][3];
}
array[i-1][0] = " ";
array[i-1][1] = " ";
array[i-1][2] = " ";
array[i-1][3] = " ";
j++;
i--;
}
}
h=i;
i=0;
ofstream outFile;
outFile.open("test2.rtf");
while(h!=0){
outFile << array[i][0] << " " << array[i][1] << " " <<array[i][2] << " " <<array[i][3]<<endl;
i++;
h--;
}
inFile.close();
return 0;
}
任何想法都会很好,因为我已经没有想法了:)