c++ 各种类型转换

1、int 2 string

法1:c++11里面的to_string

#include <string> 

std::string s = std::to_string(42);
//or 
auto s = std::to_string(42);

法2:

#include <sstream>
int a = 10;
stringstream ss;
ss << a;
string str = ss.str();

2 string 2 int 

atoi(str.c_str())
//or    
std::stoi(str)

https://www.cnblogs.com/gaobw/p/7070622.html

原文地址:https://www.cnblogs.com/zle1992/p/10164394.html