0

Possible Duplicate:
Alternative to itoa() for converting integer to string C++?
How to convert a number to string and vice versa in C++
Append an int to a std::string

I want to convert integer to string, any one help me for these conversion?

itoa(*data->userid,buff1,10);
itoa(*data->userphone,buff2,10);
Community
  • 1
  • 1
Satyam
  • 1,672
  • 3
  • 20
  • 34
  • 3
    To everyone who posted answers below, instead of feeding yet another duplicate and chasing SO scores, you'd be better voting to close it as a duplicate. – mloskot Jun 27 '12 at 09:23
  • 1
    three possibilities: http://stackoverflow.com/questions/10516196/append-an-int-to-a-stdstring/10516313#10516313 – hmjd Jun 27 '12 at 09:29

2 Answers2

9

For C++, use std::stringstream instead.

#include <sstream>

//...
std::stringstream ss;
ss << *data->userid;
std::string userId = ss.str();

or std::to_string if you have access to a C++11 compiler.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
4

If you have a C++11 compiler with the new std::to_string function you can use that. Otherwise use the std::stringstream solution by Luchian.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621