String Variable in C++

Level 291 keystrokes

Stores a name in a string and an age in an int, then chains them with << to print Alice is 25 years old.

C++ code

// string is the type for text; name stores "Alice"
1string name = "Alice";
// Stores the age 25 in the int variable age
2int age = 25;
// Each << sends the next piece, text or number, to cout
// Prints Alice is 25 years old on one line
3cout << name << " is " << age << " years old" << endl;

Output

Alice is 25 years old
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C++ code and how often they appear.

  • <× 10
  • "× 6
  • ;× 3
  • =× 2

More C++ examples at level 2

← C++ typing practice