Read 32-bit integer from binary file in C++?

前端 未结 2 884
梦毁少年i
梦毁少年i 2021-01-01 20:13

My binary file looks like this.

00000000: 0000 0803 0000 ea60 0000 001c 0000 001c
00000010: 0000 0000 0000 0000 0000 0000 0000 0000

left co

2条回答
  •  长情又很酷
    2021-01-01 20:27

    Open file in binary mode and then use read() method, something like:

    uint32_t a;
    ifstream file ("file", ios::in | ios::binary);
    if (file.is_open())
    {
         file.read ((char*)&a, sizeof(a));
    }
    

提交回复
热议问题