例如 'a' 的 ASCII 码是 97,我们可以使用
char ch = 'a';
或
char ch = 97;
使用 auto 我们可以写
auto ch = 'a';
第一种情况,但是如何在推演过程中通过数字ASCII码获取char变量?
这对我不起作用:
auto ch = '\97';
最佳答案
转义序列必须使用八进制或十六进制值
auto ch = '\141';
auto ch2 = '\x61';
更多信息https://en.cppreference.com/w/cpp/language/escape
如果你想使用十进制值,你有两种选择:
转换为字符
auto ch = static_cast<char>(97);
用户定义的文字
char operator "" _ch(unsigned long num) { return static_cast<char>(num); } //... auto ch = 97_ch;
关于c++ - 有没有办法使用十进制 ASCII 码通过自动类型推断来获取字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52932000/