source: dev/trunk/ab5.0/jenga/include/common/File.h@ 519

Last change on this file since 519 was 519, checked in by dai_9181, 17 years ago

jenga.hを追加。

File size: 743 bytes
Line 
1#pragma once
2#pragma warning(disable : 4996)
3
4
5namespace Jenga{
6namespace Common{
7
8
9class File
10{
11 const std::string filePath;
12public:
13 File( const std::string &filePath )
14 : filePath( filePath )
15 {
16 }
17
18 std::string Read()
19 {
20 HANDLE hFile = CreateFile( filePath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
21 if( hFile == INVALID_HANDLE_VALUE )
22 {
23 Jenga::Throw( filePath + " がオープンできません" );
24 }
25 int size = GetFileSize( hFile, NULL );
26
27 char *temp = static_cast<char *>(calloc( size + 1, 1 ));
28 DWORD dummy;
29 ReadFile( hFile, temp, size, &dummy, NULL );
30 CloseHandle(hFile);
31
32 std::string result = temp;
33 free( temp );
34
35 return result;
36 }
37};
38
39
40}}
Note: See TracBrowser for help on using the repository browser.