C++ Hello World Program
In this tutorial, we will learn how to write a basic Hello World program in C++ programming language.
using namespace std;
cout << "Hello World! \n Welcome to Studytonight!!\n\n";
Now let's see what we have done in the above program.
C++ Hello World Program Explained:
Let's break down the parts of the code for better understanding.
The number sign (#) at the beginning of a line targets the compiler's pre-processor.
So, in the above case, #include tells the pre-processor to include the <iostream> header.
<iostream> header defines the required libraries required to take the input and output data.
using namespace std
This tells the compiler to use the standard (
std) namespace, which includes features of the C++ Standard Library.
Similar to any other programming language, in C++, the execution of the program begins with the main function:
cout << "Hello World! \n Welcome to Studytonight!!\n\n"
In c++, the streams defined within the
iostream header, are used for the input and output operations.
cout << is used to display output to the screen. (similar to the
printf statement in C language)
cin >> is used to take input from the terminal. (similar to the
scanf statement in C language)
The main method has int as it's return type. Hence, we need to return 0 to terminate the program.
Keep Learning : )