C++ || Hello World!
This page will consist of creating the typical “hello world!” application. First, you will need to create a blank project. I am using Visual C++, but any compiler will do. When you have everything loaded up, you will start your code off by entering the headers like so into your .cpp file.
1 2 |
#include <iostream> using namespace std; |
The first line’s name stands for Input/Output Stream, and overall, these header files are used to handle the input/output process within your program.
Next, you are going to add the main function. This will generally look something like this
1 2 3 4 5 |
int main() { // YOUR CODE GOES HERE return 0; } |
Adding the line of “return 0” is an exit code, and will tell the computer that your program executed without errors.
We are halfway finished, now all we have to do is say hello to the world! You will do that by adding this line of code to your program, which basically outputs data to the screen
1 |
cout << "Hello World!" << endl; |
Notice you need to add double quotes around the text you wish to output to the screen. Also, I added a line break, also knowns as “endl;” into my function. This basically is like the <_br> tag in HTML.
So when you add everything together, your full code will look something like this
1 2 3 4 5 6 7 |
#include <iostream> using namespace std; int main() { cout << "Hello World!" << endl; return 0; }// http://programmingnotes.freeweq.com |
And there you have it. After you compile the above code (by pressing CTRL + F5 in Visual C++), you should get this as your output
Leave a Reply