Solution: Print More Greetings
This C++ program demonstrates how to print multiple lines of text to the console using the cout statement.
Header and namespace
#include <iostream>includes the input/output stream library, which allows the program to usecoutfor printing text.using namespace std;lets us use standard library objects (likecoutandendl) without writingstd::before them.
Main function
The program starts executing from the
main()function.Each
coutstatement outputs a line of text to the console, followed by<< endl;which moves the cursor to the next line.
Output lines
cout << "I'm learning C++!" << endl;prints the first message.cout << "Welcome to the machine." << endl;prints the second message.cout << "Let's write some code!" << endl;prints the third message.
Return statement
return 0;indicates successful program completion.
Solution: Print More Greetings
This C++ program demonstrates how to print multiple lines of text to the console using the cout statement.
Header and namespace
#include <iostream>includes the input/output stream library, which allows the program to usecoutfor printing text.using namespace std;lets us use standard library objects (likecoutandendl) without writingstd::before them.
Main function
The program starts executing from the
main()function.Each
coutstatement outputs a line of text to the console, followed by<< endl;which moves the cursor to the next line.
Output lines
cout << "I'm learning C++!" << endl;prints the first message.cout << "Welcome to the machine." << endl;prints the second message.cout << "Let's write some code!" << endl;prints the third message.
Return statement
return 0;indicates successful program completion.