1. 程式人生 > >C++將整形變數轉換為字串

C++將整形變數轉換為字串

#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string itos(int i)
{
    stringstream s;
    s<<i;
    return s.str();
}
int main()
{
    int a = 123;
    string ss = itos(a);
    const char* p = ss.c_str();
    cout<<ss<<" "<<p<<endl;
    return
0; }