Author Topic: Convert and int to a string  (Read 1618 times)

gavdra

  • Guest
Convert and int to a string
« on: June 05, 2015, 12:38:00 pm »
std::string myString;
int i = 150;

I have this string and this integer. I need the string to be set equal to the int, does anyone know how to do this? Thanks so much!

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: Convert and int to a string
« Reply #1 on: June 05, 2015, 04:24:04 pm »

A char buffer would be easier but to do it your way:

Code: [Select]


#include <sstream>

string myString;
int i = 150;
stringstream ss <<i;
myString = ss.str();