将整数转换为字符例如:从1到'1'

问题描述

我想将int位数转换为char(从ascii代码转换为no)。我想将其从int类型转换为char类型。 (例如:从5到“ 5”)可以吗?

解决方法

使用:

int x = 5; char c = '0' + x;  // c == '5'