How to Write the Hello World Program in CPP

Get a CPP compiler., Open a new project file, and choose "console application" on your compiler., If your compiler is a Microsoft Visual CPP, then first enter the following on the first line - #Insert "stdafx.h"., On the next line (if you've entered...

21 Steps 1 min read Advanced

Step-by-Step Guide

  1. Step 1: Get a CPP compiler.

    If you're using Windows OS, I'd suggest you to get the latest Microsoft Visual CPP.

    If you're running a linux distribution or Mac OS, get Code::
    Blocks or Bloodshed Dev CPP.

    You can obviously get them on windows too and use whichever you feel most comfortable with.
  2. Step 2: Open a new project file

    This means your "Hello World!" application would be running on the console and not your operating system. , Ignore this step if your compiler is not a Microsoft Visual CPP. , This statement declares that the terms we are going to use to write the program are included in the CPP library known as "iostream". , from your console.

    Type "int main ()" . ,, First statement in this program is
    - using namespace std;. , The last statement ends with "endl" and semi-colon.

    Now go to the next line and type cout << "Hello World!" endl
  3. Step 3: and choose "console application" on your compiler.

    , While complicated programs would include numerous functions, this is the simplest program possible and your first program ever so it just contains the main function. ,,
  4. Step 4: If your compiler is a Microsoft Visual CPP

  5. Step 5: then first enter the following on the first line - #Insert "stdafx.h".

  6. Step 6: On the next line (if you've entered the previous statement

  7. Step 7: otherwise this would be the first line)

  8. Step 8: enter #include <iostream> .

  9. Step 9: Go to the next line to enter your function

  10. Step 10: the set of instructions that defines the structure of your program and tells the compiler what to do

  11. Step 11: in this case to display the message "Hello World!"

  12. Step 12: Go to the next line and use a flower bracket "{"

  13. Step 13: to mark the beginning of this main () function.

  14. Step 14: On the next line

  15. Step 15: you have to write statements

  16. Step 16: the group of which is the function.

  17. Step 17: Each statements inside a function ends with a semi-colon ";".

  18. Step 18: Go to the next line and declare the return value of this function - return 0;

  19. Step 19: Go to the next line and use the ending flower bracket "}" to denote the end of your main function.

  20. Step 20: Press "F7" or click on the compile icon or option from the drop down menu to compile your program.

  21. Step 21: Press "CTRL" and "F5" together to run your program.

Detailed Guide

If you're using Windows OS, I'd suggest you to get the latest Microsoft Visual CPP.

If you're running a linux distribution or Mac OS, get Code::
Blocks or Bloodshed Dev CPP.

You can obviously get them on windows too and use whichever you feel most comfortable with.

This means your "Hello World!" application would be running on the console and not your operating system. , Ignore this step if your compiler is not a Microsoft Visual CPP. , This statement declares that the terms we are going to use to write the program are included in the CPP library known as "iostream". , from your console.

Type "int main ()" . ,, First statement in this program is
- using namespace std;. , The last statement ends with "endl" and semi-colon.

Now go to the next line and type cout << "Hello World!" endl

, While complicated programs would include numerous functions, this is the simplest program possible and your first program ever so it just contains the main function. ,,

About the Author

S

Sophia Cox

A passionate writer with expertise in home improvement topics. Loves sharing practical knowledge.

67 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: