整型转字符串
方法一
cpp
std::string to_string(int value); (1) (C++11起)
std::string to_string(long value); (2) (C++11起)
std::string to_string(long long value); (3) (C++11起)
std::string to_string(unsigned value); (4) (C++11起)
std::string to_string(unsigned long value); (5) (C++11起)
std::string to_string(unsigned long long value); (6) (C++11起)
std::string to_string(float value); (7) (C++11起)
std::string to_string(double value); (8) (C++11起)
std::string to_string(long double value); (9) (C++11起)方法二
cpp
string i2s(int num)
{
stringstream stream;
string result;
stream << num; // 将int输入流
stream >> result; // 从stream中抽取前面插入的int值
return result;
}字符串转整型
方法一
stoi(string str)
方法二
cpp
int s2l(string str)
{
stringstream stream;
int res;
stream << str;
stream >> res;
return res;
}TIPS
to_stirng和atoi只适用于string类型,对于char类型考虑itoa和atoi

