gpt4 book ai didi

c++ - 在 C++ 中获取硬编码内存地址的内容

转载 作者:太空狗 更新时间:2023-10-29 23:46:02 25 4
gpt4 key购买 nike

double address = 3068770752;
std::string hello = (char *)address;

错误:从类型“double”到类型“char*”的转换无效

因此,如果我使用 long 或 int 类型,这是可行的,但是对于 double 类型,这是行不通的。我该怎么做?

谢谢!

编辑:我正在用 C++ 编写 PHP 扩展程序,这是自定义函数“get_memory_data(双地址)”的“内容”,在您使用的 php 中:

<?php
$a = "hello";
$b = get_memaddress($a); //0x123456
$c = hextodec($b); //3068770752
$d = get_memdata($c); //hello

最佳答案

首先将其转换为整数:

char * p = reinterpret_cast<char *>(static_cast<uintptr_t>(address));

std::string i_cause_undefined_behaviour(p);

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

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