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

我很好奇这段代码:

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.

https://stackoverflow.com/questions/7459939/

相关文章:

c++ - 如何迭代枚举?

c++ - #pragma once 是安全的包含守卫吗?

c++ - new/delete 和 malloc/free 有什么区别?

c++ - 如何将彩色文本输出到 Linux 终端?

c++ - 空终止字符串的基本原理是什么?

c++ - 使用字符串分隔符(标准 C++)在 C++ 中解析(拆分)字符串

c++ - 删除 NULL 指针是否安全?

c++ - 如何实现 STL 风格的迭代器并避免常见的陷阱?

c++ - 在 C 中使用移位运算符进行乘法和除法实际上更快吗?

c++ - 我可以使用 break 退出多个嵌套的 'for' 循环吗?