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

C/C++ Q/A
[770] 텍스트 파일 라인단위 읽기(성공) 및 검색 실패(-.-)
통일바라기 [ironwill] 2001 읽음    2002-06-20 12:20

아래 김백일님의 친절한 설명으로 라인단위로 읽는
것은 성공(?) 했습니다.
그런데... 라인에서 특정 스트링을 검색하는 것은
실패...
 
그래서 다시 문의 드립니다.

//-------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <iostream.h>

#include "Unit1.h"
//-------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   Label1->Caption = AnsiString("현재시간 : ")
       + TimeToStr(Time());
}
//---------------------------------------------
/* 5분마다 list.txt 파일을 열어서 list_new.txt 파
일을 생성하는 모듈 ListBox1 및 ListBox2에 출력하는
이유는 이것 저것 해보느라고 쓴것이고 큰 의미는 없습
니다. */

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  Timer1->Interval = 300000;
  int i;
  TStringList *MyList = new TStringList();
  MyList->LoadFromFile("list.txt");

    ListBox1->Items->Clear();
    for (i=0; i < MyList->Count; i++) {
      ListBox1->Items->Add(MyList->Strings[i]);
      ListBox2->Items->Add(MyList->Strings[i]);
    }
  MyList->SaveToFile("list_new.txt");
  delete MyList;
}
//------------------------------------------------
/* 문제는 요놈인데...
아래 "// ListBox1->Items->Add(MyList->Strings[j]);"
인데 이걸 주석으로 처리하지 않고 실행시키면 컴파일/링크
는 정상적으로 되는데 실행하여 버튼을 클릭하면, 에러 메
시지가 발생합니다(추가로 MyList를 TempList라는 이름으
로 바꿔도 안되네요..)
Project Porject1.ext raised exception class
EStringListError with message 'List index out of
bounds(-16709743)'. Process stopped. Use Step or
Run to continue.
계속 진행하면, "List index out of bounds(-16709743)"
라는 메시지가 뜹니다
왜, 에러 메시지가 뜨는지 궁굼합니다.
또한, 주석처리를 하고 실행하면 ListBox2에는 "SYS_FIRE"
라는 스트링을 가진 라인이 출력되어야 할것 같은데 이것도
안됩니다. */

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int j;
  TStringList *MyList = new TStringList();
  MyList->LoadFromFile("list.txt");
//  ListBox1->Items->Add(MyList->Strings[j]);
    ListBox2->Items->Clear();
    for (j=0; j < MyList->Count; j++)
      if (MyList->Find("SYS_FIRE",j))
          ListBox2->Items->Add(MyList->Strings[j]);
  delete MyList;
}

+ -

관련 글 리스트
770 텍스트 파일 라인단위 읽기(성공) 및 검색 실패(-.-) 통일바라기 2001 2002/06/20
771     Re:텍스트 파일 라인단위 읽기(성공) 및 검색 실패(-.-) 김백일 2598 2002/06/20
777         Re:Re:감사합니다. 통일바라기 1881 2002/06/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.