use*_*664 7 c++ unsigned casting
我有一个变量unsigned char,它包含一个值,例如40.我想要一个int变量来获取该值.最简单,最有效的方法是什么?非常感谢你.
Oli*_*rth 12
unsigned char c = 40;
int i = c;
Run Code Online (Sandbox Code Playgroud)
据推测,你的问题肯定要多于......
小智 5
尝试以下之一,它适合我.如果您需要更具体的演员表,可以查看Boost的lexical_cast和reinterpret_cast.
unsigned char c = 40;
int i = static_cast<int>(c);
std::cout << i << std::endl;
Run Code Online (Sandbox Code Playgroud)
要么:
unsigned char c = 40;
int i = (int)(c);
std::cout << i << std::endl;
Run Code Online (Sandbox Code Playgroud)