Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "CFileDemo.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // The one and only application object
- CWinApp theApp;
- using namespace std;
- int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
- {
- int nRetCode = 0;
- HMODULE hModule = ::GetModuleHandle(NULL);
- if (hModule != NULL)
- {
- // initialize MFC and print and error on failure
- if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
- {
- // TODO: change error code to suit your needs
- _tprintf(_T("Fatal Error: MFC initialization failed\n"));
- nRetCode = 1;
- }
- else
- {
- // TODO: code your application's behavior here.
- char Buffer[101];
- ZeroMemory(Buffer,sizeof(Buffer));
- CFile File;
- CFileException fe;
- if (!File.Open(_T("my_file.txt"), CFile::modeRead, &fe)) {
- fe.ReportError();
- return FALSE;
- }
- TRY {
- while (File.Read(&Buffer, sizeof(Buffer)-1))
- {
- printf("%s",Buffer);
- ZeroMemory(Buffer,sizeof(Buffer));
- }
- File.Close();
- }
- CATCH_ALL(e) {
- File.Abort(); // will not throw an exception
- e->ReportError();
- return FALSE;
- }
- END_CATCH_ALL
- }
- }
- else
- {
- // TODO: change error code to suit your needs
- _tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
- nRetCode = 1;
- }
- return nRetCode;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement