| | |
String Concatetation
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
I have variables a, b, c = 1, 2, 3.
I would like to make it a string abc.
That above code does not work
Thanks, Regards X
I would like to make it a string abc.
C++ Syntax (Toggle Plain Text)
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
"You never stop learning." - OmniX
•
•
Join Date: Aug 2008
Posts: 77
Reputation:
Solved Threads: 16
To be a bit clearer, you can use the stringstream class like so:
For more info on stringstream check out: http://www.cplusplus.com/reference/i.../stringstream/
c++ Syntax (Toggle Plain Text)
#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 system("pause"); return 0; }
For more info on stringstream check out: http://www.cplusplus.com/reference/i.../stringstream/
mahlerfive thankyou very much for your help, much appericated.
Regards X
Regards X
"You never stop learning." - OmniX
•
•
Join Date: Mar 2008
Posts: 1,431
Reputation:
Solved Threads: 118
This isn't very related to the question, but mahlerfive, here is a few reasons why not to use system("pause") .
Hahahaha
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:
for
system("pause")
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 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:
for
system("pause")
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
"You never stop learning." - OmniX
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
sort of. Here's another link for you
I personally like (and use) the snippet from option 6
sort of. Here's another link for you
Last edited by niek_e; Aug 20th, 2008 at 11:56 am.
![]() |
Other Threads in the C++ Forum
- Previous Thread: [Linker error] undefined reference to `D3DXCreateFontA@48'
- Next Thread: TAPI
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






.. 