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

posted @ 2018-12-23 15:08  乐乐章  阅读(162)  评论(0编辑  收藏  举报