|
-
Oct 30th, 2002, 11:44 PM
#1
Thread Starter
Addicted Member
Concatenation
I know in VB I would use '&' to combine strings, but how exactly would I do it in C++?
-
Oct 30th, 2002, 11:50 PM
#2
Good Ol' Platypus
AFAIK, the plus (+) operator does it nicely in C, C++, and VB.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Oct 30th, 2002, 11:50 PM
#3
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;
}
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 30th, 2002, 11:59 PM
#4
Good Ol' Platypus
Bah! I said that! Now I get to post a useless post as well! Ha!
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Oct 31st, 2002, 12:05 AM
#5
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.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 31st, 2002, 05:32 AM
#6
Monday Morning Lunatic
Originally posted by Sastraxi
AFAIK, the plus (+) operator does it nicely in C, C++, and VB.
Not in C it doesn't 
C doesn't have strings, you have NULL-terminated blocks of memory:
Code:
char first[100] = "Hello";
const char *second = " World!";
strcat(first, second);
Of course, there are far more effective ways of doing this, but it would require messing around with malloc(), etc.
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;
};
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 31st, 2002, 07:34 AM
#7
Thread Starter
Addicted Member
" += " Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|