Work with the Text

Use string for input/output and string manipulation.

So far, we’ve worked with numbers, but C++ can handle text too. In this lesson, you’ll learn how to use string to store and manipulate sentences and words.

Goal

You’ll aim to:

  • Use string to hold text.

  • Combine strings with other variables.

  • Print personalized messages.

Create a string

Let’s turn our "Mr. A" example into something more complete, like "Alex" instead.

We’ll declare a variable using the string data type to store a full name, instead of just a single character:

Get hands-on with 1400+ tech skills courses.