MFC

파일 입출력

꼬장e 2020. 8. 2. 20:16

 

CFile file;

file.Open( _T("sample.txt"), CFile::modeCreate | CFile::modeWrite);

//읽기쓰기 작업

file.Close();

 

//쓰기

CString csBuffer= _T("test");

file.Open( _T("sample.txt"), CFile::modeCreate | CFile::modeWrite );

file.Write(csBuffer, csBuffer.GetLength() * sizeof(TCHAR));

file.Close();

 

//읽기

TCHAR szBuffer[1024] = {0,};

file.Open( _T("sample.txt"), CFile::modeRead );

file.Read( szBuffer, 1024 * sizeof(TCHAR) );

file.Close();

 

//예외처리

TRY

{

  TCHAR szBuffer[1024] = {0,};

  Cfile file;

  file.Open( _T("sample.txt"), CFile::modeCreate | Cfile::modeWrite );

  file.Write( szBuffer, 1024 * sizeof(TCHAR) );

  file.Close();

}

CATCH(CFileException e )

{

  e->ReportError();

  e->Delete();

}