C++/C:數字轉成字串, 字串轉成數字

redis_v發表於2016-01-12
數字轉成字串:

用C++的streanstream:

#include <sstream>
#include <string>
string num2str(int i)
{
   stringstream ss;
   ss<<i;
   return ss.str();
}</strong></span>

字串轉成數字:

用C++的streanstream:

int str2num(string s)
 {   
    int num;
    stringstream ss(s);<span style="display: none; width: 0px; height: 0px;" id="transmark"></span>
    ss>>num;
    return num;
}</span>

相關文章