1

Possible Duplicate:
How do I concatenate multiple C++ strings on one line?

How would I take:

string test1 = "Hello ";
string test2 = "World!";

and concatenate them to make one string?

Community
  • 1
  • 1
yankees96
  • 37
  • 1
  • 1
  • 5

2 Answers2

9

How about

string test3 = test1 + test2;

Or maybe

test1.append(test2);
cnicutar
  • 178,505
  • 25
  • 365
  • 392
3

You could do this:

string test3 = test1 + test2;

Or if you want to add more string literals, then :

string test3 = test1 + test2 + " Bye bye World!"; //ok

or, if you want to add it in the beginning, then:

string test3 = "Bye bye World!" + test1 + test2; //ok
Nawaz
  • 353,942
  • 115
  • 666
  • 851