I have variables a, b, c = 1, 2, 3.

I would like to make it a string abc.

int a = 1;
int b = 2;
int c = 3;

string abc = "";

abc = a + "" + b + "" + c ;

count << abc;

That above code does not work :(

Thanks, Regards X

Use std::ostringstream class (from <sstream> header) and its member function str().
It's so simple ;)..

To be a bit clearer, you can use the stringstream class like so:

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

int main() {
    stringstream ss; // our stringstream object
    int a = 1, b = 2, c = 3;
    ss << a << b << c; // we insert a b and c into the stringstream
    cout << ss.str(); // call str() to get the string out
    return 0;

For more info on stringstream check out: http://www.cplusplus.com/reference/iostream/stringstream/

Perfect example, thankyou.

mahlerfive thankyou very much for your help, much appericated.

Regards X

On the topic of pause, you got one for cls?

Thanks, Regards X


I just pissed myself, im expecting serious input at option 4 and boom ahhh a good laugh.

But on a serious note, I liked option 1 - clear and simple.

Agree, disagree?

On a side note:

we should use cin.get()?

Or something like make a function an int and return 0, something like that but cins the way to go i gather

ahh good laugh off to bed goodnight people

I like option 1 in all it's simplicity, but it's main disadvantage is that the cursor is at the bottom of the screen after using this method. So the next time you write anything to the screen, it will be written at the bottom rather then the top.
I personally like (and use) the snippet from option 6

we should use cin.get()?

sort of. Here's another link for you :)

I just read the whole 'thread' abit over whelming but I gathered:

cin.get(); // when no output after

//when output is after
#include <istream>

void ignore_line ( std::istream& in )
  char ch;

  while ( in.get ( ch ) && ch != '\n' )

Thanks for the help and info once again niek_e!

This question has already been answered. Start a new discussion instead.