DeletedUser
Guest
Hi folks
Past few weeks I've been working on how to understand c++ language and finally I've found some success. C++ can be difficult at first but it requires patience and a bit of brains. Anyone can learn C++ but the only thing it requires is patience.
Now the simplest compiler in my opinion which is best for newbies is Code Block. The link for code block download is: http://sourceforge.net/projects/codeblocks/files/Binaries/10.05/Windows/codeblocks-10.05mingw-setup.exe/download
After you download it, you have yourself a compiler. It may not be the best but it's user friendly. Now create a project which uses Console Application template. Fill in the details and now open your Project.
Now you will see the simplest program:
1 #include <iostream>
2
3 using namespace std;
4
5 int main ()
6 {
7 cout << "Hello Grepolis" << endl;
8 return;
9
10 }
In this tutorial I will be breaking this program word by word, code by one until you understand all of it's definition and purposes.
This include <iostream> is called a preeprocesser directive. Pree Proccessor directive means that it's going to include a file iostream in this program which we're going to need later. The next line you'll see a blank line. Blank lines are not needed but are used to make your program neater and easier to read. Just like a book or a magizine. There's no limit to blank lines. You can have a million of them or 1 of them.
Under that blank is Using Namespace Std;. And believe it or not it does not stand for sexually transmitted diseases. Instead it stands for Standard library. And that's pretty much saying this: we're going to be using all the standard things in c++ plus, nothing fancy.
int main ()
6 {
7 cout << "Hello Grepolis" << endl;
8 return;
9
10 }
This entire thing is called a function. Computer programs are made up of functions. Functions are things you want the computer to do. For example if you're making a program to play sounds, you'll need a function which programs the computer to play sounds.. As you can see functions are just things you want the computer to do.
Every computer program start with a function code main. This is how your computer knows where to start. Main tells the computer the order of your program so it won't be confused and mess up the program with unnecessary errors. So that is why it's so crucial to name your function main.
In order to make a function you must write what type of data you're going to be working with. Functions typically do some sort of calculations. For example find the mass of an index or calculate the vosallity of something or w/e. It usually wants something back or an answer. So since we're going to be working with intergers we're going to need to put "Int" in our function.
Don't worry about these brackets. You just need em lads. Now you need squiggly brackets : {
}
Between the squiggly brackets are statements. All functions are made up of statements and all statements are basically instructions. Each instructions needs to end with a semi colon(.
The first statement is cout. That's called an output stream object and is basically use to write words on the computer screen. That's how we're able to type hello world on the computer screen.
This << is called the conjuction stream operator which is used to take all this stuff in the right of it and prints it out on the screen. Cout << "Hello grepolis" << . Endl; means end line which pretty much means go to the next line.
That's all the meaning of this program. If you have any question pm me or make a comment. A simple program may look simple but it's complex. It's easy when you understand the code and know what they do. Rep me if you think this was helpful. I may make more tutorial depending on the comments.
Past few weeks I've been working on how to understand c++ language and finally I've found some success. C++ can be difficult at first but it requires patience and a bit of brains. Anyone can learn C++ but the only thing it requires is patience.
Now the simplest compiler in my opinion which is best for newbies is Code Block. The link for code block download is: http://sourceforge.net/projects/codeblocks/files/Binaries/10.05/Windows/codeblocks-10.05mingw-setup.exe/download
After you download it, you have yourself a compiler. It may not be the best but it's user friendly. Now create a project which uses Console Application template. Fill in the details and now open your Project.
Now you will see the simplest program:
1 #include <iostream>
2
3 using namespace std;
4
5 int main ()
6 {
7 cout << "Hello Grepolis" << endl;
8 return;
9
10 }
In this tutorial I will be breaking this program word by word, code by one until you understand all of it's definition and purposes.
This include <iostream> is called a preeprocesser directive. Pree Proccessor directive means that it's going to include a file iostream in this program which we're going to need later. The next line you'll see a blank line. Blank lines are not needed but are used to make your program neater and easier to read. Just like a book or a magizine. There's no limit to blank lines. You can have a million of them or 1 of them.
Under that blank is Using Namespace Std;. And believe it or not it does not stand for sexually transmitted diseases. Instead it stands for Standard library. And that's pretty much saying this: we're going to be using all the standard things in c++ plus, nothing fancy.
int main ()
6 {
7 cout << "Hello Grepolis" << endl;
8 return;
9
10 }
This entire thing is called a function. Computer programs are made up of functions. Functions are things you want the computer to do. For example if you're making a program to play sounds, you'll need a function which programs the computer to play sounds.. As you can see functions are just things you want the computer to do.
Every computer program start with a function code main. This is how your computer knows where to start. Main tells the computer the order of your program so it won't be confused and mess up the program with unnecessary errors. So that is why it's so crucial to name your function main.
In order to make a function you must write what type of data you're going to be working with. Functions typically do some sort of calculations. For example find the mass of an index or calculate the vosallity of something or w/e. It usually wants something back or an answer. So since we're going to be working with intergers we're going to need to put "Int" in our function.
Don't worry about these brackets. You just need em lads. Now you need squiggly brackets : {
}
Between the squiggly brackets are statements. All functions are made up of statements and all statements are basically instructions. Each instructions needs to end with a semi colon(.
The first statement is cout. That's called an output stream object and is basically use to write words on the computer screen. That's how we're able to type hello world on the computer screen.
This << is called the conjuction stream operator which is used to take all this stuff in the right of it and prints it out on the screen. Cout << "Hello grepolis" << . Endl; means end line which pretty much means go to the next line.
That's all the meaning of this program. If you have any question pm me or make a comment. A simple program may look simple but it's complex. It's easy when you understand the code and know what they do. Rep me if you think this was helpful. I may make more tutorial depending on the comments.