2010
09-25

C++ lesson 0 – compiler

In this lesson I will help you do decide which C++ compiler select. I will describe here Microsoft Visual C++ Express, Microsoft Visual Studio Profesional, Codeblocks and g++. Of course you can use different one if you want.

Compilers:

Microsoft Visual Studio Profesional - This is full featured Microsoft compiler for most of modern programing languages. It's not free. I don't recomend that for begin users. Microsoft Visual C++ Express - This is limited version of Microsoft Vsiaul Studio Profesional. It's free. You can download it from www.microsoft.com/express/Downloads. It's perfect for beginer programes which are going to write only for windows. Codeblocks - this is free and opensource compiler, it support lot of languages. It work on most popular OS, so it's prefect if you want to write program for few OS. For example if you want to write program for Windows, Linux and Mac. You can download it from www.codeblocks.org. If you are going to install it at windows be sure that you will download version with mingw (The true is that Codeblock by it's own it's not compiler, it's only IDE witch use compier g++). g++ - Linux command line compier. It's good if you are familiar with command line and if you want to fast compile one file program. Tipical usage look like this: g++ program/program.cpp -o program/program You can also compie program witch have more files, but for that I recommend to use makefile in that case. Instalation on most Linux dysributions look diffrerent. At Linux Debian you can install it by typing as root: apt-get install g++ It's strongly not recommended for beginer users.

Writing first program:

After you install compier you need to create new project to start working with it. Usualy something like select file -> project -> new. and few times click new. I'm sure that you can handl that and there is no need to describe that step by step. If everitying go right then you will be able to compie that code:
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. cout<<"hello world"<<endl;
  8. return 0;
  9. }
  10.  
So if you write that code and press "compire and run" you should see something like this: Sometimes compier do not add pause at end of program, so program will close in blink of eye after it start. In that case you can add system("pause"); before return 0; so program will pause before end. The code will look then like this:
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. cout<<"hello world"<<endl;
  7. system("pause");
  8. return 0;
  9. }
  10.  
If that code don't work then there is something wrong with your compiler or you put it in wrong place. In that case you can try to reinstall compiler or ask somebody for help. If everything go well then you can go to next lesson.

1 Coments.

  1. Regularly group buy Wrap up is beginning to feel somewhat old. Wonder background over voucher the pro’s will not want one to know. The Key For fashion. Recent write-up shares the important information about fashion in addition , the reasons why you have to take action right now.

Leave a Reply

  ( Ctrl+Enter )