我在尝试将我的输入解释为十六进制数时遇到了一些麻烦。例如,如果给定 40A2
的输入,并假设我有一个大小为 216 的数组,我将如何访问以下示例?
arr[0x40A2] //this is simply accessing the array at binary 0100 0000 1010 0010
which is at index 16546
我只是遇到了一点麻烦,因为当程序接收到用户的输入时,数字会被解释为 ASCII 值,并且需要被解释为十六进制值。
最佳答案
你如何阅读输入? C++ 标准输入流理解std::hex
modifier :
unsigned int index;
std::cin >> std::hex >> index;
关于c++ - 将输入解释为十六进制数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15253401/