|
아래의 코드를 실행하면, output.out이라는 파일을 읽다가 에러가 나네요. Population at generation no. -->1 문장까지는 잘 읽어들이다가, 공백으로 되어 있는 줄을 읽으면서 에러가 납니다. 이유를 모르겠네요. 조언 부탁드립니다.
output.out 내용은 아래와 같습니다.
Results in a file
----------------------------------------------------
Statistics at Generation 0 ->
--------------------------------------------------
Population at generation no. -->1
---------------------------------------------------
Generation No. ->1
------------------------------------------------------
variables (real 2 binary 0) fitness (2) constraint (2) penalty rank cublen || variables fitness constraint penalty rank cublen
47.447468 -51.827564 4858.2236 -2363.7244 -2.09e+01 -2.13e+01 4.22e+01 65 0.000000 |**| 23.010815 -22.312325 986.918823 -336.367157 42 -3.57e+00 -9.99e+00 1.36e+01 65055.167969 ......
다음은 소스 코드 입니다.
/* Source code */
nvar = 2;
int i, j, k, l;
char s[1500];
int Temp_Num_of_Row, Temp_Num_of_Col;
ofstream outfile("Variables for generations.txt");
ifstream infile("output.out");
TStringList *strlist = new TStringList;
strlist->Delimiter = ' ';
Num_of_Col = 0;
while(!infile.eof())
{
infile.getline(s, sizeof(s));
strlist->DelimitedText = s;
if(strlist->Strings[0] == "Generation")
{
for(l=0;l<2;l++)
infile.getline(s, sizeof(s));
Temp_Num_of_Row = 0;
infile.getline(s, sizeof(s));
strlist->DelimitedText = s;
while(strlist->Count>3)
{
for(i=0;i<nvar;i++)
outfile<<strlist->Strings[i].c_str()<<" ";
Temp_Num_of_Row++;
outfile<<endl;
infile.getline(s, sizeof(s));
strlist->DelimitedText = s;
}
Num_of_Col++;
}
outfile<<endl;
}
outfile<<endl;
outfile.close();
infile.close();
Edit12->Text = "Complete";
|