【发布时间】:2014-01-07 17:33:47
【问题描述】:
请原谅模糊的标题(我不知道如何解决这个问题)。无论如何,在我的代码中,我明确声明了一些变量,两个是有符号/无符号 int 变量,另一个是有符号/无符号 char 类型变量。
我的代码:
#include <iostream>
int main(void)
{
unsigned int number = UINT_MAX;
signed int number2 = INT_MAX;
unsigned char U = UCHAR_MAX;
signed char S = CHAR_MAX;
std::cout << number << std::endl;
std::cout << "The size in bytes of this variable is: " << sizeof(number) << std::endl << std::endl;
std::cout << number2 << std::endl;
std::cout << "The size in bytes of this variable is: " <<sizeof(number2) << std::endl << std::endl;
std::cout << U << std::endl;
std::cout << "The size in bytes of this variable is: " << sizeof(U) << std::endl
<< std::endl;
std::cout << S << std::endl;
std::cout << "The size in bytes of this variable is: " <<sizeof(S) << std::endl << std::endl;
std::cin.get();
std::cin.get();
return 0;
}
抱歉,由于长度过长,代码被打乱了,但我的问题是我的 char 变量没有“打印”到我的输出中。它以字节为单位输出它们的大小,但无论我做什么,我似乎都无法让它工作。此外,第二个 char 变量 (signed (S)) 打印看起来像三角形的东西,但没有别的。
【问题讨论】:
-
将它们转换为 int 以显示值而不是 ascii 字符。
标签: c++ char outputstream