|
초보 님이 쓰신 글 :
: 이런내용들이 가득찬 텍스트 파일이 있습니다
: -----------------------------------------------
: 씨플플빌더(bolandforum) -> FUBU20100107
: MFC매니아(microsoft) -> GIOR1020102
: (...이하생략)
: ------------------------------------------------
: 여기에 TXT파일을 한줄씩 읽어 3개씩 뽑아서 저장하고싶습니다
:
: 씨플플빌더 bolandforum FUBU20100107
: MFC매니아 microsoft GIOR1020102
:
: TStringList 클래스에 차곡차곡 넣으면 될꺼같은데
:
: 텍스트 파일 읽을때 주로 사용하는 방법좀 알려주시면 감사하겠습니다
허접,단순하지만 저는 주로 아래처럼 해결하고 있습니다...
메모장에서 코딩한것이어서 오탈자 있을지도 모릅니다.
char ch;
AnsiString str,str1,str2,str3;
AnsiString DataFileName;
int pos;
FILE *Data_File;
DataFileName = "text.txt";
Data_File = fopen(DataFileName.c_str(), "r");
while(!feof(Data_File))
{
//
str.SetLength(100);
ch = 0;
pos = 0;
while(true)
{
fread(&ch, 1, 1, Data_File);
if(feof(Data_File))
{
goto READ_END;
}
else
if(ch == '\n')
{
str.c_str()[pos] = 0;
break;
}
else
{
str.c_str()[pos++] = ch;
}
}
//씨플플빌더(bolandforum) -> FUBU20100107
pos = str.Pos("(");
str1 = str.SubString(1, pos-1); //씨플플빌더
str = str.SubString(pos+1, str.Length());
pos = str.Pos(")");
str2 = str.SubString(1, pos-1); //bolandforum
pos = str.Pos("->");
str3 = str.SubString(pos+3, str.Length()); //FUBU20100107
//
str = "";
}
READ_END:
fclose(Data_File);
|