bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/C++/C++ Tutorial
C++•C++ Tutorial

C++ String Concatenation

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind C++ String Concatenation?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ firstName = "John ";
3Order

Put the learning moves in the order that makes the concept easiest to apply.

In the example above, we added a space after firstName to create a space between John and Doe on output.
The + operator can be used between strings to add them together to make a new string.
String Concatenation

String Concatenation

The + operator can be used between strings to add them together to make a new string. This is called concatenation :

Example

string firstName = "John ";
string lastName = "Doe";
string fullName = firstName + lastName;
cout << fullName;

In the example above, we added a space after firstName to create a space between John and Doe on output. However, you could also add a space with quotes ( " " or ' ' ):

Example

string firstName = "John";
string lastName = "Doe";
string fullName = firstName + " " + lastName;
cout << fullName;

Append

A string in C++ is actually an object, which contain functions that can perform certain operations on strings. For example, you can also concatenate strings with the append() function:

Example

string firstName = "John ";
string lastName = "Doe";
string fullName = firstName.append(lastName);
cout << fullName;

Tip

A list of other useful string functions, can be found in our String Functions Reference .

Previous

C++ Strings

Next

C++ Numbers and Strings