First answer posted by Bentley907 at 08/24/2011 03:52
14 Answers
Bentley907
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.
Open a new project file, and choose "console application" on your compiler. This means your "Hello World!" application would be running on the console and not your operating system.
If your compiler is a Microsoft Visual CPP, then first enter the following on the first line - #Insert "stdafx.h". Ignore this step if your compiler is not a Microsoft Visual CPP.
On the next line (if you've entered the previous statement, otherwise this would be the first line), enter #include . This statement declares that the terms we are going to use to write the program are included in the CPP library known as "iostream".
Go to the next line to enter your function, the set of instructions that defines the structure of your program and tells the compiler what to do, in this case to display the message "Hello World!" from your console. Type "int main ()" .
Go to the next line and use a flower bracket "{", to mark the beginning of this main () function.
On the next line, you have to write statements, the group of which is the function. First statement in this program is - using namespace std;.
Each statements inside a function ends with a semi-colon ";". The last statement ends with "endl" and semi-colon. Now go to the next line and type cout
Go to the next line and declare the return value of this function - return 0;
Go to the next line and use the ending flower bracket "}" to denote the end of your main function.
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.
Press "F7" or click on the compile icon or option from the drop down menu to compile your program.
Press "CTRL" and "F5" together to run your program.