how do i add a int to a string

c++, string

Solution

Use a stringstream.

#include <iostream>
#include <sstream>
using namespace std;

int main () {
  int a = 30;
  stringstream ss(stringstream::in | stringstream::out);

  ss << "hello world";
  ss << '\n';
  ss << a;

  cout << ss.str() << '\n';

  return 0;
}

Problem

i have a string and i need to add a number to it i.e a int. like: ``` string number1 = ("dfg"); int number2 = 123; number1 += number2; ``` this is my code: ``` name = root_enter; // pull name from another string. size_t sz; sz = name.size(); //find the size of the string. name.resize (sz + 5, account); // add the account number. cout << name; //test the string. ``` this works... somewhat but i only get the "*name*88888" and... i don't know why. i just need a way to add the value of a int to the end of a string

Original source