You can not use C++ I/O classes (fstream) in Handmade project, because it disabled C++ exceptions ("-EHa-" compiler argument). Either remove this argument so C++ exception are allowed, or use C file I/O (fopen/fread/fwrite).
To use debug I/O functions Casey implemented, do this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 | int something[] = { 1, 2, 3 };
bool32 ok = DEBUGPlatformWriteEntireFile("debug.txt", something, sizeof(something));
Assert(ok);
// ... later read it back:
int array[3];
debug_read_file_result fresult = DEBUGPlatformReadEntireFile("debug.txt");
if (fresult.Contents != 0)
{
Assert(fresult.ContentsSize == sizeof(array));
memcpy(array, fresult.Contents);
DEBUGPlatformFreeFileMemory(fresult.Contents);
}
// use array here
// ...
|
Instead of memcpy you could cast it to array type and use it directly:
| // ... later read it back:
int* array = 0;
debug_read_file_result fresult = DEBUGPlatformReadEntireFile("debug.txt");
Assert(fresult.Contents != 0); // check that file is loaded
// use array here
// ...
// later close it
DEBUGPlatformFreeFileMemory(fresult.Contents);
|