<分区>
#include <iostream>
int main() {
std::cout << 'hello';
return 0;
}
这个程序的输出是:
1701604463
我想知道为什么它实际上运行了,尽管编译器给出了一条警告消息:character constant too long for its type
。
这些数字到底是什么意思,它们是垃圾数字吗?
标签 c++
<分区>
#include <iostream>
int main() {
std::cout << 'hello';
return 0;
}
这个程序的输出是:
1701604463
我想知道为什么它实际上运行了,尽管编译器给出了一条警告消息:character constant too long for its type
。
这些数字到底是什么意思,它们是垃圾数字吗?
最佳答案
是multicharacter literal其类型为 int
。
Multicharacter literal, e.g. 'AB', has type int and implementation-defined value.
关于c++ - 在 std::cout 中使用单引号打印字符串实际上打印的是数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58294540/