In order to program in C++ you will need:
- Computer.
- Linux or Windows Operating System.
- C++ compiler.
The best way to learn how to write programs is ... to actually start writing them. Unlike some other, also cool programming languages, such as python which is are called 'interpreted' language, C++ is a bit more difficult to start with. Every time we have a problem to solve using C++, we will need to carry out the following steps:
- Writing a code in a text editor (or IDE).
- Compile it (if there is problem with our syntax, the compiler will tell us about it).
- Correct any problems found by the compiler (missing semicolon, brace, etc.).
- Run the code to test it.
C++ is very fussy about details (syntax), so I advise that you type each code I present here watching every character (comma, semicolon, lef/right brace etc) as you do so.
NOTE
Do NOT copy and paste the code ever. You develop your skills by typing the code as well.
NOTE
You probably do not know what compilation is and there will be many things that will baffle you in the beginning. Do not worry about it now. Just take those things for granted. Explanations to those bits will come later. Now, it is all about repeating the process and having some fun with it From now on, you are the boss.
Here is your initial code structure we will use starting every program (well, sometimes we will add some more stuff, but the below will always be present).
Pic. 1.1 - C++ Program Structure
#inlcude <iostream>
using namespace std;
int main() {
return 0;
}
If you have carefuly typed in the code above into your editor or software development kit, and saved it as ex001.cpp, now compile it. If you did well, the compiler will not show any error. If you use linux box you can use the following command (do not type in the '$' sign):
$ g++ -o ex1 ex001.cpp
If you use Microsoft Windows and codeblocks IDE, just open a new project, type the code in and save it. Then click the icon in the menu that has a green arrow similar to the one used on DVDs ;). If you see no errors in the bottom of the page we're good.