Multiple Lines
In the previous exercise, we learned to output one line of text. Often, however, we need to output multiple lines. We can do this in several ways:
1. Using multiple std::cout
commands:
std::cout << "First line" << std::endl;
std::cout << "Second line" << std::endl;
2. Or using one std::cout
command with multiple std::endl
:
std::cout << "First line" << std::endl << "Second line" << std::endl;
Both methods will output the same result:
First line
Second line
The first method is clearer and more commonly used, because each output line is on a separate line in the code.
Instructions
Write a program in the main
function that outputs the following three lines of text:
I'm learning C++
It's awesome
I'll be a programmer!
Start programming for free
3/5