C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[55230] Re:List index out of bounds (0) 가 발생합니다
kylix [] 3260 읽음    2008-11-21 18:13
아래 라인에서 에러가 발생하겠네요...
if(strlist->Strings[0] == "Generation")
읽어드린 줄자체가 공백이라면 strlist는 비어있죠... 그런데 0번인덱스에 접근하실려고 하니까 에러가 발생한것입니다.

만두박사 님이 쓰신 글 :
: 아래의 코드를 실행하면, 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";

+ -

관련 글 리스트
55229 List index out of bounds (0) 가 발생합니다 만두박사 4081 2008/11/21
55230     Re:List index out of bounds (0) 가 발생합니다 kylix 3260 2008/11/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.