阅读量:123
在C++中,可以使用强制类型转换或者使用标准库函数stoi()将char类型转换为int类型。
- 使用强制类型转换:
char c = '5';
int num = static_cast<int>(c);
- 使用
stoi()函数:
#include
char c = '5';
int num = std::stoi(std::string(1, c));
这里通过将char类型转换为std::string类型,然后使用stoi()函数将字符串转换为整数类型。