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