Hello World
Now let's write our first C++ program! Every C++ program will have a similar basic structure:
#include <iostream>
int main() {
}
Let's explain the individual parts:
#include <iostream>
- This tells the program that we want to use input/output functions likecout
for text output.int main()
- This is the main function of the program. Every C++ program must have amain
function.{}
- Curly braces designate a code block. Everything between them belongs to themain
function.
Now let's show how to output text in C++.
std::cout << "Hello!" << std::endl;
std::cout
- is an abbreviation for character output stream.<<
- is the operator that follows."Hello!"
- is the text we want to output.std::endl
- serves to end the line.
Instructions
Insert the following command into the main
function between the curly braces and press run.
std::cout << "Hello world!" << std::endl;
Start programming for free
2/5