gpt4 book ai didi

c++ - std::cout<< ' ' <
转载 作者:行者123 更新时间:2023-12-01 14:04:26 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Multicharacter literal in C and C++

(6 个回答)



Multi-character constant warnings

(6 个回答)


去年关闭。




我是 C++ 的新手。我想知道为什么我会收到 A2105376B当我运行以下代码时:

#include <iostream>
int main(){

std::cout <<'A' << ' ' <<'B'<<std::endl;
return 0;

}

提前致谢!

最佳答案

' '是具有类型 int 和实现定义值的多字符字 rune 字。

看来您的意思是一字节字 rune 字 ' '或字符串文字 " "
来自 C++ 标准(2.13.3 字 rune 字)

2 A character literal that does not begin with u8, u, U, or L is an ordinary character literal. An ordinary character literal that contains a single c-char representable in the execution character set has type char, with value equal to the numerical value of the encoding of the c-char in the execution character set. 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 xecution character set, is conditionally-supported, has type int, and has an implementation-defined value.



这是一个演示程序,如果它由三个空格的 ASCII 值初始化,则输出一个整数对象。
#include <iostream>

int main()
{
int x= 0x202020;

std::cout << x << '\n';
std::cout << ' ' << '\n';

return 0;
}

程序输出是
2105376
2105376

关于c++ - std::cout<< ' ' <<std::endl;输出一个数字;为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61147494/

24 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com