c++ - 如何在 C++ 中将字符串更改为多字 rune 字?

标签 c++

假设我有以下内容:

int i = 'abc';

如果有办法将字符串更改为多字 rune 字,如下所示

char* str="abc";
int j = ?

(我们也想设置 int j= 'abc')。

但是如何用字符串做到这一点呢?

最佳答案

C99 6.4.4.4/10:

The value of an integer character constant containing more than one character (e.g., 'ab'), or containing a character or escape sequence that does not map to a single-byte execution character, is implementation-defined."

C++11 2.14.3/1:

A multicharacter literal has type int and implementation-defined value.

因此,在不知道您的具体实现是做什么的情况下,您无法重现相同的结果。一旦您知道它的作用,您应该能够毫无问题地自行计算 j

关于c++ - 如何在 C++ 中将字符串更改为多字 rune 字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28160535/

相关文章:

java - Android NDK,保持实时 C++ 对象

计算值集合的标量的函数的 C++11esque 签名

c++ - QT:使用字段间规则进行表单验证

c++ - Stringstream 将值读入 double 失败?

c++ - 如何实现基于关系矩阵的逻辑

c++ - std::string 到 std::chrono time_point

c++ - 如何从友元类访问抽象类的私有(private)成员?

c++ - 覆盖 QAbstractItemModel::index 并访问 std::map

c++ - 使用脉冲编码调制将数据从一台电脑传输到另一台电脑

c++ - 内存段中存储的全局变量和静态变量在哪里?