如何将 unsigned int (UINT32) 转换为 const char。
我尝试转换它,但因为类型不安全,当指针大于预期时会崩溃。
那么我该如何正确处理呢?
unsigned int p = 0x32422342;
strLocation = QString::fromUtf8((char*)p, sizeof(p));
顺便说一句,如果我离开 Actor 阵容,编译器会出现异常:
cast to `const char*`from smaller integer type `UINT32` (aka `unsigned int`) [-Wint-to-pointer-cast]
有什么建议吗?该值只是一个随机数,只是为了说明。
最佳答案
你的指针可能有 64 位长,这就是你的编译器提示的原因......你确定你的 32 位代表一个好的地址吗?可能不是。
关于c++ - 如何在 C++ 中将 unsigned int(指针)转换为 const char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26776888/