TL ; DR:
The console is a panel that displays important messages, like errors, for developers.
In C++, we use
cout <<to print something to the console. For example, this program:cout << 13;
prints
13to the console.
Full lesson:
The console is a panel that displays important messages, like errors, for developers.
Much of the work the computer does with our code is invisible to us by default. If we want to see things appear on our screen, we can print to our console directly.
cout << :
In C++, we use cout << to print something to the console. For example, this program:
cout << 13;
prints 13 to the console.
When you run this program, this is what you'll see in your console:
13
We refer to the data printed to the console as the output of the program.
End of line:
In C++, there is a special keyword named endl (short for end of line) which we can print to the console using cout <<.
Whenever we print an endl, we insert a new line in the console. It's like pressing Enter in your text editor to move to the next line.
We usually use endl when we want to print multiple values on separate lines:
cout << 1 << endl;
cout << 2 << endl;
cout << 3;
The ouput of this program would be:
1
2
3
Assignment
Follow the Coding Tutorial and let's print some values to the console!
Hint
Look at the examples above if you get stuck.
Free plan: 30 tutor messages. Premium is unlimited.
