0

Possible Duplicates:
Alternative to itoa() for converting integer to string C++?
c++ integer->std::string conversion. Simple function?

how can i convert an integer i=123456789 into a string value? I am working in c++/ubuntu. THX

I am working in ubuntu 9.10

Community
  • 1
  • 1
linuxx
  • 1,487
  • 4
  • 16
  • 17
  • 1
    C++ is a language that has a standard. Most of the questions on the core language are not OS related, and even if they are, it is much better to just tag the question than add the information to the title. Also, the specific distribution of linux will not make a difference. It does not make sense to include `ubuntu` in the title and `ubuntu 9.10` in the body. At any rate the exact compiler version would help more: `g++-4.2` (or whatever the compiler in ubuntu 9.10 is by default) – David Rodríguez - dribeas May 10 '11 at 12:55

2 Answers2

2

You can do:

std::stringstream ss;
ss<<i;
std::string s = ss.str();
Asha
  • 11,002
  • 6
  • 44
  • 66
0

You can use lexical_cast:

int i = 123456789;
std::string s = boost::lexical_cast<std::string>(i);
int j = boost::lexical_cast<int>(s)
Mike Kwan
  • 24,123
  • 12
  • 63
  • 96