In the last two tutorials, you learnt about C++ Data-types & Operators and Strings. In this tutorial, you'll go into more depth about variables and how to get input from the user. Let's get started!
Variables
Variables are used to store values. Variables are so central to programming that you'll almost never come across which doesn't use variables.
A good analogy for the variable is a box. You can imagine the name of the variable as the label on the box, and the value of the variable as what's stored inside it.
Let's create a new string variable called name:
string name = "Commonlounge";
The above is equivalent to saying: Store the value "Commonlounge" in variable name.
So how do we know that the variable actually exists? Simply display the variable with cout command:
type=codeblock|id=cpp_string_variablecout << name << endl;// Output - Commonlounge
Yippee! Your first variable! :)