我有一个80元素char数组,我正在尝试特定的元素,integer并得到一些数字错误.十六进制的数组元素40是0xC0.当我尝试将它分配给integer我得到十六进制0xFFFFC0时,我不知道为什么.
char tempArray[80]; //Read in from file, with element 40 as 0xC0
int tempInt = (int)tempArray[40]; //Output as 0xFFFFC0 instead of 0x0000C0
Run Code Online (Sandbox Code Playgroud)
Bat*_*eba 14
根据您的实现,一个char在C++类型是要么一个signed类型或一个unsigned类型.(C++标准要求实现选择任一方案).
为了安全起见,请unsigned char在您的情况下使用.
| 归档时间: |
|
| 查看次数: |
718 次 |
| 最近记录: |