Hello guys, thought I'd start off with a nice simple tutorial on making your first C++ Program. I'm only 14 so your probably better off to go Google a more detailed tutorial .
I'm assuming you have a compiler at this time, if you don't then go and torrent Microsoft Visual Studio. Personally i use 2003 .Net because it best fits my needs, but any is good really.
After you have a compiler open up a new Win32 Console Application and name it whatever you want.
If you're using MSVS, when you start a new project in the settings select 'Empty Project' to stop any precompiled headers.
Please Read: DON'T Just copy and paste! You WONT learn anything unless you retype it out later, type it out yourself. You will learn a hell of a lot more then just copy and pasting.
Code:
#include <iostream>
using namespace std;
Don't worry about this too much for now, but iostream and std contains some basic functions that we're going to be using.
Next Add~
int main() is the what our program will execute(use) when you run it.
int stands for integer which means that we're going to have to return a value in main() else we will get compile errors!
"{" and "}" are the opening and closing brackets for "main()", { is where main() starts and } is where main() ends.
These aren't just for main() though! You can use these for any of your own voids/integers/methods that you create, for instance
"void myVoid() { }"
Here the brackets do exactly the same thing, anyway, moving on~
Add the rest of the code into your main() integer.
{ Remember to add the code in between the brackets }
Code:
cout << "Hello World!" << endl;
cin.get();
return 0;
cout stands for "console output" and is used to output data onto a console (The black box looking thing).
Anything after the operator "cout <<" is outputted onto the console, because we're outputting a string we will use speech marks.
The full code "cout << "Hello World!" << endl;"
outputs 'Hello World!' and endl means end line so it goes to the next line.
cin.get() basically 'pauses' the programming until you press a key, stopping our program from just flashing open and close;
"return 0;" Remember what i said earlier about main() being an integer and needs to return a value, well this just returns the value 0.
Now the code should look like this:
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
cin.get();
return 0;
}
Notes
We use ";" to declare the end of a line, you can also however use it to seperate different things and put your code on one line like this:
Code:
cin << "Hello World!" << endl; cin.get(); return 0;
I don't want to go into too much detail about cin, it stands for "console input", try googling it .
Ending Program
Now we are finished, this is what our program should do on a console screen:
~Mr. Bond
P.S. If there are any errors in this tutorial please contact me immediately