-
鸿蒙传说
取决于您想要做什么:要将值读入ascii代码,可以编写char a = 'a';int ia = (int)a; /* note that the int cast is not necessary -- int ia = a would suffice */转换字符'0' -> 0, '1' -> 1等等,你可以写char a = '4';int ia = a - '0';/* check here if ia is bounded by 0 and 9 */
-
慕尼黑5688855
在ASCII代码中,数字(数字)从48..你要做的就是:int x = (int)character - 48;
-
Smart猫小萌
C和C+总是将类型提升到至少int..此外,字符文字也是类型的。int在C和char在C+中。您可以将char类型,只需将其赋值给int.char c = 'a'; // narrowing on Cint a = c;