繁体   English   中英

如何写一个空指针的内容?

[英]How to write the content of a void pointer?

这怎么可能cout逐位存储在该位void中CPP指针?

void * r = malloc(k*8);
size_t count;
//Print string under byte form with bytes separated by space
cout << mpz_export (r, &count, 1, sizeof(char), 1, 0, cypher.get_mpz_t());

这个cout只写地址。

我想你在找这个

Function: size_t mpz_out_str (FILE *stream, int base, const mpz_t op)

在stdio流流上输出op,以基数为字符串。 base参数的范围从2到62或-2到-36。对于2..36范围内的base,将使用数字和小写字母。 对于-2 ..- 36,使用数字和大写字母。 对于37..62,使用数字,大写字母和小写字母(按重要性顺序)。 返回写入的字节数,如果发生错误,则返回0

可以在这里找到更多信息: https : //gmplib.org/manual/I_002fO-of-Integers.html

像这样

char* ptr = (char*)mpz_export(r, &count, 1, sizeof(char), 1, 0, cypher.get_mpz_t());
for (int i = 0; i < count; ++i)
    cout << (unsigned)(unsigned char)ptr[i] << ' ';
cout << '\n';

由于数据是char数据,因此必须将void指针强制转换为char指针。 然后要将输出视为无符号整数(我想是您想要的),则必须将每个char转换为unsigned char ,然后转换为unsigned

如果要十六进制输出,则只需添加通常的格式代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM