Add the basic program structure
Every C++ program consists of at least one function: main()
. The main()
function is the starting point for the program. In the main()
function, we'll be using the cout
statement to print the "Hello World!" message on the screen.
Add the following code to main.cpp
:
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
return 0;
}
The #include <iostream>
statement includes the iostream library to use the cout statement for printing the message to the terminal screen.
The using namespace std;
statement allows us to use the standard namespace without having to type std:: every time.