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
[67278] Re:TFileStream 파일 가져오기 질문좀요
송신영 [palindrome] 1074 읽음    2012-05-22 09:23
stTest 구조체를 올려보세요.
String을 사용한 경우 FileStream으로 저장하기 위해서는 추가적인 작업이 필요합니다.
저장할 때 먼저 Int 형으로 String 의 길이를 저장하고 String의 c_str() 형으로 데이터를 저장해주고
나중에 읽을 때 int형의 길이를 읽어 해당 길이만큼 문자열을 읽고 이 문자열을 다시 String 변수에 넣어주는 방식을
사용해야합니다.

축구 님이 쓰신 글 :
: st_Test stTest;

:  stTest.nTestSize = AData.Length;
:  stTest.DateTime = now;
:  stTest.strIP = strIP;
:  stTest.strPORT = strPORT;

:  TFileStream *pSendHeaderData = new TFileStream(Edit1->Text, fmOpenWrite|fmShareExclusive);

:  pSendHeaderData->Seek(0, SEEK_END);

:  pSendHeaderData->Write((void *)&stTest, sizeof(st_Test));
:  pSendHeaderData->Write(&AData[0], AData.Length);

:  delete pSendHeaderData;
:
: 파일에 저장하고요, 불러들이는게 어려운데요
:
: TFileStream *pFileStream = new TFileStream(OpenDialog1->FileName, fmOpenRead);
: st_Test *stTest = new st_Test();
:
: pFileStream->Position = 0;
:
:     while(pFileStream->Position < pFileStream->Size)
:     {
:         pFileStream->Read(stTest , sizeof(st_Test ));  //쓰레기값 들어감
:
:         TBytes ReadBytes;
:         ReadBytes.Length = stTest ->nFileTotalSize;
:         pFileStream->Read((void *)ReadBytes[0], ReadBytes.Length);  //집어넣은 값말고, 쓰레기
:                                                                                                                                                        값이 들어옴
:         TDateTime now;
:         now = stTest ->strDateTime;  //여기서 오류
:
:         String strIP;
:         String strPORT;
:         strIP = stTest ->strIP;
:         strPORT = stTest ->strPORT;
:
:         PrintReceveList(now, strIP, strPORT, ReadBytes);   //출력함수
:     }
:     delete stTest ;
:     delete pFileStream;
:
: 이렇게 했는데 저 위에 왜 쓰레기 값이 들어올까요???  도저히 모르겠어요

+ -

관련 글 리스트
67263 TFileStream 파일 가져오기 질문좀요 축구 1018 2012/05/21
67278     Re:TFileStream 파일 가져오기 질문좀요 송신영 1074 2012/05/22
67280         Re:Re:TFileStream 파일 가져오기 질문좀요 축구 1005 2012/05/22
67281             Re:Re:Re:TFileStream 파일 가져오기 질문좀요 송신영 1589 2012/05/22
67282                 Re:Re:Re:Re:TFileStream 파일 가져오기 질문좀요 축구 1199 2012/05/22
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.