In my program one of my function returns a vector<int> ... I want to save it in to a vector<string>.
itoa function does not seem to work here. Is there anything that can be done regarding this.
Thanks in Advance.

10 Years
Discussion Span
Last Post by iamthwee

I would imagine you could create a vector of char*. Go through your vector of integers, use itoa on each individual integer to create a string, then push that new string onto your vector. Note that itoa converts to a char*, not a C++-style string. itoa wouldn't work on an entire vector directly. You have to convert the elements one by one and push them onto the new vector of type char*. If you want a vector of C++-style strings instead, you'd have to then create one from the char* returned by itoa for each element of the integer vector.


Just use the function

string IntToString ( int number )
  std::ostringstream oss;

  // Works just like cout
  oss<< number;

  // Return the underlying string
  return oss.str();

and include the header file: #include <sstream>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.