How to Make a Hello World Program in C++
The hello world program in C++ contains the basics components in C++ program. Hello World Program is a program that will display "Hello...
http://ww-tikus.blogspot.com/2015/01/how-to-make-hello-world-program-in-c_31.html
This program is contains some lines of code, and i will explain this line of codes one by one.
This is example of hello word codes in C++ :
#include<iostream>Save the above codes in cpp format (ex. HelloWorld.cpp), and compile and run it using C++ compiler. If using Command Prompt, you will can compile it with this command :
using namespace std;
int main()
{
cout << "Hello World!";
return 0;
}
g++ -o <program_name> HelloWorld.cpp
And now just run your program :
#include<iostream>, this will includes the basic standard input/output library in C++.
using namespace std;, this line of code is used in C++ programs that use the standard library.
int main(), every program in C++ must have a main() function with return values. In this case we will use integer as return values of this main program. The main function is the method in C++ programs to start the execution. The two curly brackets are used to determine the beginning and the end of the codes in a function.
cout << “Hello World”;, a simple expression that will print "Hello World" text in your screen. cout is the standard output stream in C++.
return 0;, The return statement causes the function finish its execution. In this case, this return statemant will stop the execution of the main function. Using zero indicates that everything went okay, and if using one is usually indicates something has gone wrong. As i said before, actually this return statement is not only integer, it depends on what you declare of your main functions.