|
"Test.txt" 파일이 없어서 그런것 같은데요
TFileStream 생성 옵션 입니다. 참조하세요
fmCreate Create a file with the given name. If a file with the given name exists, open the file in write mode.
fmOpenRead Open the file for reading only.
fmOpenWrite Open the file for writing only. Writing to the file completely replaces the current contents.
fmOpenReadWrite Open the file to modify the current contents rather than replace them.
fmCreate 파일이 있으면 쓰기용으로 열고, 없으면 만듭니다.
fmOpenRead 파일을 읽기만 가능하게 엽니다.
fmOpenWrite 파일을 쓰기만 가능하게 엽니다.
fmOpenReadWrite 파일을 읽고 쓸수 있게 엽니다
그럼..
초보자 님이 쓰신 글 :
: 안녕하세요 TPersisternt 차트 공부하다가 Button1 을 누를때 memo1에 소스가 기록되서 나오고
: Button2 누를때 memo2를 소스를 test.txt에 기록하고 마지막으로 Button3 누를 시 문자 'A'라는 글자를 Test.txt의 맨
: 앞부분에 붙이는 역할 수행 하는 소스 예제를 쳐봤는데요
:
: 우선 Button1 누르는건 실행이 되지만 Button2 누르거나 Button3 누르면 test.txt cannot open 매세지 출력하게 되네요
: 먼가 문제 있는지 확인 부탁드립니다
:
:
: <소스>
:
: //---------------------------------------------------------------------------
:
: #include <vcl.h>
: #pragma hdrstop
:
: #include "TPersistent1.h"
: //---------------------------------------------------------------------------
: #pragma package(smart_init)
: #pragma resource "*.dfm"
: TForm1 *Form1;
: //---------------------------------------------------------------------------
: __fastcall TForm1::TForm1(TComponent* Owner)
: : TForm(Owner)
: {
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
: TMemoryStream *theMemStream;
: theMemStream = new TMemoryStream;
: try{
: //파일을 로드한다
: theMemStream->LoadFromFile("TPersMain.cpp");
: //42째 문자의 위치를 찾는다
: theMemStream->Seek(0,soFromBeginning);
: //스트림으로부터 그문자를 불러온다
: Memo1->Lines->LoadFromStream(theMemStream);}
: __finally {delete theMemStream;}
:
: }
: //---------------------------------------------------------------------------
: void __fastcall TForm1::Button2Click(TObject *Sender)
: {
: TFileStream *theFileStream;
: theFileStream = new TFileStream("Test.txt",fmOpenWrite);
: Memo1->Lines->SaveToStream(theFileStream);
: delete theFileStream;
:
: }
: //---------------------------------------------------------------------------
: void __fastcall TForm1::Button3Click(TObject *Sender)
: {
: char theChar='A';
: TMemoryStream *m;
: m = new TMemoryStream;
: m->WriteBuffer(&theChar,sizeof(char));
: TFileStream* f = new TFileStream("Test.txt",fmOpenRead);
: m->CopyFrom(f , f->Size);
: delete f;
: m ->SaveToFile("Test.txt");
:
: }
:
:
: 자세한 설명 부탁드립니다 그리고 중요한부분이거나 공부해야 할 참고사항 주석으로 달아주시면 좋은정보로 쓸께요
:
: 항상 좋은 정보 감사합니다
|