bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

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

C++ Strings

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind C++ Strings?

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.

___ greeting = "Hello";
3Order

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

A string variable contains a collection of characters surrounded by double quotes ( "" ):
For example, "Hello World" is a string.
Strings are used for storing text/characters.

Strings are used for storing text/characters.

For example, "Hello World" is a string.

A string variable contains a collection of characters surrounded by double quotes ( "" ):

Example

Create a variable of type string and assign it a value:

string greeting = "Hello";

To use strings, you must include an additional header file in the source code, the <string> library:

Example

// Include the string library #include <string> // Create a string variable string greeting = "Hello"; // Print the string cout << greeting;

Note

Strings can contain multiple words, spaces, and punctuation:

Example

string greeting = "Hello and welcome!";
cout << greeting;

Previous

C++ Operator Precedence

Next

C++ String Concatenation