当我用单引号括起一个字符串时,C++ std::cout 打印奇怪的字符
C++ std::cout printing wierd characters when I enclose a string with single quotations
当我尝试 std::cout << ', ';
时,我得到了 11296
,我知道我应该用 ", "
将它括起来,但为什么我得到的是数字?
你有两个单引号字符(逗号和 space)。
这种多字符文字的值取决于您的编译器等。
在这种情况下,ASCII 值是 44 和 32,
11296 = 44 * 256 + 32
即。两个字节一起理解为 16 位整数
根据标准(N4296,2.13.3 字符文字,强调我的):
An
ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter
literal, or an ordinary character literal containing a single c-char not representable in the execution character
set, is conditionally-supported, has type int, and has an implementation-defined value.
"有条件支持" 是 (1.3.5)
program construct that an implementation is not required to support
当我尝试 std::cout << ', ';
时,我得到了 11296
,我知道我应该用 ", "
将它括起来,但为什么我得到的是数字?
你有两个单引号字符(逗号和 space)。
这种多字符文字的值取决于您的编译器等。
在这种情况下,ASCII 值是 44 和 32,
11296 = 44 * 256 + 32
即。两个字节一起理解为 16 位整数
根据标准(N4296,2.13.3 字符文字,强调我的):
An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal, or an ordinary character literal containing a single c-char not representable in the execution character set, is conditionally-supported, has type int, and has an implementation-defined value.
"有条件支持" 是 (1.3.5)
program construct that an implementation is not required to support