I know in VB I would use '&' to combine strings, but how exactly would I do it in C++?
Printable View
I know in VB I would use '&' to combine strings, but how exactly would I do it in C++?
AFAIK, the plus (+) operator does it nicely in C, C++, and VB.
If you are using strings from the string class, then you can just + them together.
VB Code:
#include <iostream> #include <string> using namespace std; int main() { string s = "Hello "; string t = "there!"; s += t; cout << s << endl; return 0; }
:)
Bah! I said that! Now I get to post a useless post as well! Ha!
Yeah, the only difference is that you probably know what you are talking about when you answer questions, where as I am just a good guesser.
:)
Not in C it doesn't ;)Quote:
Originally posted by Sastraxi
AFAIK, the plus (+) operator does it nicely in C, C++, and VB.
C doesn't have strings, you have NULL-terminated blocks of memory:Of course, there are far more effective ways of doing this, but it would require messing around with malloc(), etc.Code:char first[100] = "Hello";
const char *second = " World!";
strcat(first, second);
Actually, there's nothing to stop you making your own string-type structure and some associated functions::)Code:struct string_t {
char *ptr;
size_t allocated;
size_t used;
};
" += " Thanks :D