How to Concatonate strings?

Started by
6 comments, last by MetaKnight 21 years, 6 months ago
How do you Concatonate strings? like so Monkey + power = monkeypower
Advertisement
I believe in string.h there is a function called strcat() look it up...it might be what you need.

Either that, or if you are using strstream, I think (but am not totally sure) you can do something like

string << "monkey" << "power";

-=Lohrno
What language?


The world holds two classes of men -- intelligent men without religion, and religious men without intelligence. - Abu''l-Ala-Al-Ma''arri (973-1057; Syrian poet)
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
thanks!
In C++, and how would i concatonate without using count, sopse i have a 3d text display in my program.

like this:
string3 = string1+string2;

  #include <string>using namespace std;string str1 = "monkey";string str2 = "power";string str3 = str1 + str2; // str3 == "monkeypower"str2 = "monkey" + str2;    // str2 == "monkeypower" toostr1 += "power";           // str1 == "monkeypower" too  


Or


  #include <sstream>#include <string>using namespace std;stringstream ss;ss << "monkey" << "power";string str = ss.str();  


Do not use strstream.



Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
You can do it two ways without using cout (I think thats what you meant...)

strcat() (I forget the exact parameters...I think it''s something like: string3 = strcat(string1, string2) )

or you can do sprintf(string3,"%s%s",string1, string2);

(sprintf works like printf to a string)

(yes I think I meant stringstream, fruny knows what he''s talking about )

-=Lohrno
look at this
"...and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces."----------Scott Meyers, "Effective C++"
amazing!
thanks!

This topic is closed to new replies.

Advertisement