使用带有 std::cout 的单引号打印字符串实际上打印了数字

Using single quotes with std::cout for printing a string actually prints numbers

本文关键字:打印 字符串 实际上 数字 单引号 cout std      更新时间:2023-10-16
#include <iostream>
int main() {
std::cout << 'hello';
return 0;
}

此程序输出为:

1701604463

我想知道它为什么实际运行,尽管编译器给出了一条警告消息:character constant too long for its type.

这些数字实际上意味着什么,它们是垃圾数字吗?

它是类型为int的多字符文本。

多字符文本,例如"AB",具有 int 和 实现定义的值。