[英]Converting an output from Hexadecimal to Decimal in c++
我试图找到数组元素的内存地址,但是输出结果却是十六进制的。 如果您能告诉我如何将其转换为小数输出,我将不胜感激。
这是代码,
#include<iostream>
using namespace std;
int main()
{
int a[4];
cout << "Address of a[0] = " << &a << endl;
cout << "Address of a[1] = " << &a[1] << endl;
cout << "Address of a[2] = " << &a[2] << endl;
cout << "Address of a[3] = " << &a[3] << endl;
cin.get();
return 0;
}
在C ++ 11中,您可以uintptr_t
为uintptr_t
,例如
cout << "Address of a[0] = " << static_cast<uintptr_t>(&a) << endl;
uintptr_t
专门用于表示任何可能的指针,因此该解决方案是可移植的。
我不知道C ++ 98/03中的可移植解决方案,尽管通常(但并非总是) size_t
为size_t
。 相关: 将指针转换为整数 。
编辑
查看http://en.cppreference.com/w/cpp/types/integer以及C ++标准18.4.1标头<cstdint>提要[cstdint.syn] ,它看起来像uintptr_t
是可选的 。 我不知道是否存在没有定义它的实现,为什么不选择不定义它。 欢迎任何意见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.