本文主要是介绍c++ int 转string的多种方式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.int a = 10;
char *intStr = itoa(a);
string str = string(intStr);2.int a = 10;
stringstream ss;
ss << a;
string str = ss.str();3. C++11 (推荐,如果支持的话)#include <string> std::string s = std::to_string(42);4. C++ 98即可 (不支持C++11就用这个或者2,233 )#include <sstream>#define SSTR( x ) static_cast< std::ostringstream & >( \( std::ostringstream() << std::dec << x ) ).str()5. Boost#include <boost/lexical_cast.hpp>
原文:https://blog.csdn.net/zmdsjtu/article/details/80360398
这篇关于c++ int 转string的多种方式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!