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?

0

2 Answers 2

9

How about

string test3 = test1 + test2;

Or maybe

test1.append(test2);
Sign up to request clarification or add additional context in comments.

5 Comments

I have that ^ But it errors.. Do you know why? And I have guess defined before this.
@yankees96 Or even guess += c;.
@yankees96 What is the error.
And how are guess and c defined ?
Ah, it was a simple error somewhere else that we messing with me. Thank you very much!!
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.