tongqingliu

保持学习的态度

C++任意数值类型转string

#include<iostream>
#include<sstream> 
using namespace std;

template<class T>
string ToString(T value)
{
    stringstream strstream;
    strstream.str("");
    strstream << value;
    return strstream.str();
}

int main()
{
    unsigned long x = 123456;
    string strx = ToString(x);
    printf("x = %s\n", strx.c_str());
    return 0;
}

posted on 2020-03-13 15:30  tongqingliu  阅读(413)  评论(0编辑  收藏  举报

导航