1 字节整数数据类型
1 byte integer data type
我写了以下代码:
#include <iostream>
#include <iomanip>
#include <stdint.h>
using namespace std;
int main()
{
uint8_t c;
cin >> hex >> c;
cout << dec << c;
return 0;
}
但是当我输入 c
时——12 的十六进制——输出也是c
的。我期待12。后来我才知道:
uint8_t
通常是unsigned char
的typedef。所以它实际上是将c
读作 ASCII 0x63。
是否有一个 1 字节整数在执行 I/O 时表现为整数而不是字符?
不是我知道的。
可以使用更宽的整数类型执行 I/O,并根据需要使用范围检查和强制转换。
恐
怕我也不知道办法,但是将十六进制数读取为整数类型可以按如下方式完成:
#include <iostream>
using namespace std;
int main () {
short c;
cin >> std::hex >> c;
cout << c << endl;
return 0;
}
相关文章:
- 防止主数据类型C++的隐式转换
- 什么是 16 字节有符号整数数据类型?
- C++11 中是否有实际的 4 位整数数据类型
- 创建一个带有限制的数字数据类型,一个介于 -10 和 10 之间的整数
- 如何仅接受整数并忽略其他数据类型
- 编译器是否有可能检测整数溢出或其他数据类型溢出的可能性
- 1 字节整数数据类型
- 对应于 AS3 编号(整数)的C++数据类型是什么?
- 小数、双精度、整数等数据类型的范围
- 在整数数据类型和连续两个字符类型之后.第 2 个字符的数据类型跳过..为什么
- C++如何将整数和浮点等数据类型封送为字节字符串
- C++字符串 DD:HH:MM:SS 到整数数据类型
- 表示本机有符号和无符号整数大小的数据类型
- 有没有一种方法可以为非整数创建枚举数据类型
- 对于一般用途的整数,我应该使用什么数据类型?
- 布尔数据类型vs整数数据类型来表示真值
- C++11 在map<key,value>中存储值(整数和字符串)的多种数据类型的最简单方法?
- 如果我将数字存储为整数数据类型,如何检查另一个数字中是否存在一个数字
- 从双精度数据类型获取特定整数的方法
- 超过 C++ 的最大整数数据类型