Hello World in C++!
Get started with your first program!
1. In this tutorial I’ll show you how to start your very first C++ program!
If you don’t have the appropriate tools, you can head over to Tutorial on getting started with C++ to get started right away!
2. You will also learn the structure of a C++ program.
Hello World
1. Open up your text editor, or IDE and type this in to an empty file/project.
2. Run it using the appropriate commands found in my Tutorial on getting started with C++ depending on your environment and you should see Hello World in your terminal!
So what just happened?
I’ll explain what the previous code just meant.
Includes the library iostream that contains the definitions for the input/output streams
using namespace std allows us to use the entities that correspond to std. This is something you’ll usually have in all your programs.
{
This is the main function declaration where all programs start executing. in other words, whatever commands you have after this declaration will execute sequentially.
This statement “cout” represents the output stream in C++ which outputs a sequences of characters to the stream which is usually the terminal.
“Hello World” is called a string.
\n indicates a newline.
}
This return statement causes the main function to finish executing. The zero simply means that the program finished successfully. There are other codes, but I’ll explain those later.
Structure of a C++ Program
With the basic Hello World program you should follow the following guidelines when creating any program.
using namespace std;
int main()
{
statements to execute your program
return 0;
}
Additional Resources
Getting Started for Programming shows you what you need in order to start programming.
Introduction to what C++ really is
Congratulations! You’ve made your first program! If you are having any trouble feel free to post a comment and I’ll respond promptly!



May 7th, 2008 at 8:06 pm
I still remember when I started this program way back! It’s pretty straightforward! If anyone has any questions, feel free to post them here!
May 9th, 2008 at 3:57 pm
Great article!
June 16th, 2008 at 10:36 pm
Hey awesome blog! Know anyone who would be interested in part time admin’ing a Linux box? Hit me up!
May 3rd, 2009 at 4:16 pm
Hi, I am programming knowledge in Java but wish to expand my programming knowledge into C/C++. After reading your post on this site, I was so exited to be able to start programming in C++. Everything went well except that the console window that prints the out was not displayed when I ran the application. Instead, I had the following message below the box where I typed my code
(
“Hello – Debug” uses an invalid compiler. Skipping…
Nothing to be done.
)
and the “Build Lod” on the taskbar above it was highlighted. I don’t know if the problem is mind or not. I would be very grateful if you respond to my posting.
Thanks in advance for your help.
May 3rd, 2009 at 11:03 pm
Can you provide more information?
What operating system are you using? Linux, Windows, Mac OSX?
Have you installed gcc yet in order to compile using g++?
The above code should work fine. The file should be called something like main.c and compiled with ‘g++ main.c’.
Getting started for programming might help.
Tell me if your problem still persists!
July 20th, 2009 at 1:55 pm
Hi, Diego!
Thanks alot for your help. My computer was bad, so I could not get in touch with the forum members. Actually, I read some tutorials I had save and had the problem sorted out. I’m a little comfortable program both in C and C++ now. I’m using Windows Vista.
Again, thanks for your reply.