c++ - 单引号在 C++ 中用于多个字符时有什么作用?

标签 c++ quotes

我很好奇这段代码:

cout << 'test'; // Note the single quotes.

给我一​​个 1952805748 的输出。

我的问题:输出是内存中的地址还是什么?

最佳答案

这是一个多字 rune 字。 19528057480x74657374,分解为

0x74 -> 't'
0x65 -> 'e'
0x73 -> 's'
0x74 -> 't'

编辑:

C++ standard, §2.14.3/1 - Character literals

(...) An ordinary character literal that contains more than one c-char is a multicharacter literal . A multicharacter literal has type int and implementation-defined value.

关于c++ - 单引号在 C++ 中用于多个字符时有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7459939/

相关文章:

c++ - 未找到 : You need to find "" to view the source for the current call stack frame

delphi - 从字符串中去掉引号

java - 将变量放入引号后的打印周期

c - 如何用转义序列替换单引号和双引号(对于传递给 strtok 的字符串)

mysql - MySQL 中何时使用单引号、双引号和反引号

c++ - 不区分大小写的 std::string.find()

c++ - 'for' 的增量表达式没有任何效果

mysql - MySQL 中何时使用单引号、双引号和反引号

c++ - 用于将 void 指针转换为指向类型的指针的操作的术语是什么?

c++ - QWeb引擎 : handling get and post requests when a runJavaScript is performed