【问题标题】:Using single quotes with std::cout for printing a string actually prints numbers [duplicate]使用带有 std::cout 的单引号来打印字符串实际上会打印数字 [重复]
【发布时间】:2020-02-06 05:22:42
【问题描述】:
#include <iostream>

int main() {
  std::cout << 'hello';
  return 0;
}

这个程序的输出是:

1701604463

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

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

【问题讨论】:

    标签: c++


    【解决方案1】:

    它是multicharacter literal,其类型为int

    多字符文字,例如'AB',具有 int 类型和 实现定义的值。

    【讨论】:

      猜你喜欢
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      • 2013-03-13
      • 2013-06-14
      相关资源
      最近更新 更多