|
struct st_Test
{
int nTestSize;
double DateTime;
AnsiString strIP;
AnsiString strPORT;
st_Test()
{
nTestSize= 0;
DateTime = 0;
}
};
구조체는 이렇게 쓰고있어요.이것 저것 해보느라 조금 바뀌었어여 밑에것도 바꿔 놀게요
송신영 님이 쓰신 글 :
: stTest 구조체를 올려보세요.
: String을 사용한 경우 FileStream으로 저장하기 위해서는 추가적인 작업이 필요합니다.
: 저장할 때 먼저 Int 형으로 String 의 길이를 저장하고 String의 c_str() 형으로 데이터를 저장해주고
: 나중에 읽을 때 int형의 길이를 읽어 해당 길이만큼 문자열을 읽고 이 문자열을 다시 String 변수에 넣어주는 방식을
: 사용해야합니다.
:
: 축구 님이 쓰신 글 :
: : st_Test stTest;
: :
: : stTest.nTestSize = AData.Length;
: : stTest.DateTime = now.Val;
: : 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 ->nTestSize ;
: : pFileStream->Read((void *)ReadBytes[0], ReadBytes.Length); //집어넣은 값말고, 쓰레기
: : 값이 들어옴
: : TDateTime now;
: : now.Val = stTest ->DateTime;
: :
: : AnsiString strIP;
: : AnsiString strPORT;
: : strIP = stTest ->strIP;
: : strPORT = stTest ->strPORT;
: :
: : PrintReceveList(now, strIP, strPORT, ReadBytes); //출력함수
: : }
: : delete stTest ;
: : delete pFileStream;
: :
: : 이렇게 했는데 저 위에 왜 쓰레기 값이 들어올까요??? 도저히 모르겠어요
|