Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
HI! i have a program where i need to add 2 strings to be more specific.
i want to do this
char string1[80] = '[' + string2 + ']';language = C++. Thanks for any help.

when you mean add 2 strings do you mean like
char str1[20] = 'HELLO WORLD';
char str2[20] = 'MY NAME IS JAMES';and make it say HELLO WORLD MY NAME IS JAMES in str1 or 2? ( the [20] is just an example i know the sentence is longer :-P )
If yes, then use the concactante function.
I havnt worked in C++ in a few months, so ill go bust open my books and find out how to use the concactinate function.
GIMPS

Well it really all depends on what you have to use it for. Using Character Arrays as strings, means you need to use Character Array functions for concantenation:
char string2[10] = "wow";
char string1[80] = "[";
strcat(string1,string2);
strcat(string1,"]");
cout << string1 << endl; // outputs [wow]Now, if you want to have serious ease of use and advanced features that are easy to implement (you can implement them with Character Arrays as well, but it requires you to reinvent these wheels), use the basic_string that c++ has:
string string_2 = "wow";
string string_1 = "[" + string_2 + "]";
cout << string_1 << endl; // outputs [wow]the following program shows you how to use both of these:
-------------------
#include <string>
#include <iostream>using namespace std;
-------------------int main(int argc, char* argv[])
{
char string2[10] = "wow";
char string1[80] = "[";
strcat(string1,string2);
strcat(string1,"]");
cout << string1 << endl;string string_2 = "wow";
string string_1 = "[" + string_2 + "]";
cout << string_1 << endl;char dummy;
cin >> dummy;
return 0;
}
-------------------
Enjoy,
Chi
"They mostly come at night...mostly"

![]() |
VB WinXP Controls
|
Web Interface : Stocks
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |