Variables

2.1 - Variable intro


Variables are used to store values. A variable must have a type. The type we use for storing text is std::string.

This line defines an std::string variable called name and initializes the value to "Tom".

std::string name{"Tom"};

The variable can then be printed using std::cout.

Task

Change the name from Tom to Jerry.

  • Replace std::string name{"Tom"}; with std::string name{"Jerry"};.
#include <iostream> #include <string> int main() { std::string name{"Tom"}; std::cout << "Hello, " << name << std::endl; }