Attention: Since i am a member of a lot of communitys you may see my guides often but if it is not posted by blaze or energyforce you can be sure someone stole it.
Also i use the german Visual Studio so you have to translate the words you dont know or compare the screenshots with your screen :]
Getting Started with c++
Requirements:
- Visual Studio 2010 *
(create, edit, run and compile your project)
- Notepad++
(edit single code files)
Lets configure Visual Studio
1. Download and install Visual Studio 2010 Express or Professional. Leave all install settings like they are and you are good to go.
2. For this step i have made a couple of screenshots which say more than 1000 words (imageshack)
(.cpp files contain c++ source code. A project contains many different files which work together as a whole program. .cpp files are part of a project)
3. If your project is ready to run you can test compile it with strg+f5. As soon as an Error appears the compiler ends the process and throw an exception which you can see in the white box at the bottom of Visual Studio
4. If the test run ends without an exception you can build your program with the f7 key. Navigate to your storage location. You will see a new folder which contains both every different file used by your project and the compiled exe.
Lets write a bit code
Our first program will launch the command line and print "Hello World".
The source looks like this
using namespace std;
this line will give us acces to the namespace std. You can imagine a namespace as some kind of a three:
namespace = roots
directories = branches
Objects (Attributes and Methodes) = leaves
#include <iostream>
this will include the headerfile <iostream>.
Headerfiles contain declarations of Methods and Functions
int main()
{
}
This is a function which we named main().
main is if not other definied the starting point of a program.
int declares the returnvalue of the function (in this case 0).
cout << "Hello World" << endl;
cout is an object or a method of the namespace std.
cout is used to display text in the command line. it can also look like this
cout << "Hello " << x << " how are you?";
Using Variables
int is the datatype of the variable. Int is used for plain numbers. There are several other Datatytpes
bool 0 or 1, true or false, yes or no ...
double used for long numbers which contains numbers after the comma
string a word for example
char your variable can hold one char
x is the name of the variable
the operator = assign the 10 to the variable x
Operators are +, -, = and all other chars which do an operation with your code :].
I think most of you will now variables from math
x = 10
x + 10 = 20
What you should know else
c++ is NOT a "scripting language". You write code and not "scripts"!!!!! Scripts are used as a runtime by other programs!
Sourcecode is translated to native machinecode or bytecode which our machine can read and execute.
Now you can use Visual Studio and create your own easy programs but if you want to learn memory reading (as example) i advice you to go deeper into the matter.
How much bits are a byte?
How much bits are used by the different datatypes (int, char and so on)?
Such things are important to know but for the first time its ok to only know about what you see on your screen.
After all i am also a total beginner but i will fight my way through all this partly boring stuff. In the future i will release many more guides.
Since i am german my english is not the best. Please correct me per pm if i made any mistakes. Its my goal to get better and for this i need your help.
What you can except in my next guides
if and else
manipulators
ascii