gpt4 book ai didi

c++ - 在 C++ 中获取地址的内容

转载 作者:行者123 更新时间:2023-11-27 23:28:02 24 4
gpt4 key购买 nike

如果我没有指向它的指针,在 C++ 中是否有可能获取内存中地址的内容,但我确实有地址本身作为 uint_32

谢谢

编辑

我正在写这些地址,并试图查看我的 write() 函数是否正常工作,所以我想手动读取这些地址。上面提到的“内容”是 uint64_t 类型,这是我尝试做的,但这给了我一个Segmentation Fault

uint64_t *contents = reinterpret_cast<uint64_t*>(start_address);
cout<< hex << "Contents: " << *contents << endl;

我在这里做错了什么?

最佳答案

不确定可移植性,但您可以使用 reinterpret_cast<> .例如

uint_32 adrs;
int *p = reinterpret_cast<int*>(adrs); // int* should be 32-bit for portable code

关于c++ - 在 C++ 中获取地址的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7917166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com