给定以下代码。
#include <cstdint>
#include <iostream>
#include <limits>
int main()
{
int8_t x = 5;
std::cout << x << '\n';
int y = 5;
std::cout << y;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.get();
return 0;
}
我的输出结果是一个三叶草和数字5。如果固定宽度整数是整数,为什么会输出其数字的ASCII字符符号?
编辑:刚刚发现这种行为只发生在8位固定宽度整数上?这是编译器的行为吗?
std::is_same<std::int8_t, signed char>::value
- Ryan Haining