【发布时间】:2018-07-23 16:23:06
【问题描述】:
我是 C++ 领域的新手。
在线memcpy(combined + 14 + 40, pThirdPart, size); 抛出
在 Memcpy.exe 的 0x0FB046EE (vcruntime140d.dll) 处引发异常: 0xC0000005:访问冲突读取位置0x00544000。
为什么会这样?
const long size = 8294400;
char firstPart[14] = "3412345";
char secondPart[40] = "daffda";
char *thirdPart = new char[size];
sprintf_s(thirdPart, size, "Test TEst tset ... and other symbols");
BYTE *pFirstPart = reinterpret_cast<BYTE*>(&firstPart);
BYTE *pSecondPart = reinterpret_cast<BYTE*>(&secondPart);
BYTE *pThirdPart = reinterpret_cast<BYTE*>(&thirdPart);
BYTE *combined = new BYTE[(size + 14 + 40)];
memcpy(combined, pFirstPart, 14);
memcpy(combined + 14, pSecondPart, 40);
memcpy(combined + 14 + 40, pThirdPart, size);
【问题讨论】:
-
必问问题:你为什么不直接使用
std::string? -
什么是
BYTE? -
我猜想
reinterpret_cast<BYTE*>(&thirdPart);应该是reinterpret_cast<BYTE*>(thirdPart);- 虽然我真的不确定所有这些reinterpret_casts 的意义是什么 -
@nvoigt Windows Data Types: typedef unsigned char BYTE;
-
std::byte 是一个东西。
标签: c++