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 like cout for text output.
  • int main() - This is the main function of the program. Every C++ program must have a main function.
  • {} - Curly braces designate a code block. Everything between them belongs to the main 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

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

2/5

Hello World | Start Coder