A first look at C++

  Computers      |  Downloads      | Linux          | Home           | Feedback        | Links               

So you want to learn some C++!? well, hopefully this site should be able to help you start of, but before I go into it, I want to make a few simple observations:

1. No website can teach you the full C++ Language, its bigger then English!  (well, maybe!). If your serious about learning C++ I suggest that you go to your nearest book store and buy the biggest C++ bible you can find. Some books that have helped me include the 'Sams' teach your self range. 

2. You will need a compiler for your C++ programs, a compiler is a piece of software that converts the C++ language into machine code that can be executed. I recommend Borland C++ compilers as they are fast, have loads of features and great support.

3. As usual there is more then one way to do things, that rule also applies to C++. Although there is a rough guide book to the language, there are many different variations of it, so you will just have to find the one that suits you.

Contents:

    1. Introduction

bullet

What does C++ do?

bullet

Who uses C++?

bullet

How long does it take to learn?

    2. What you need

bullet

Which Compiler?

bullet

Computer specs

bullet

Other sources of Info

    2. The Basics

bullet

A first look at C++

bullet

Expiation of the program

bullet

Standard Input & output

    3. 32-bit Programming

bullet

What's that!?

bullet

Where do I start?

bullet

Short Example

    4. Short Examples

 

 

 

Introduction

What does C++ do?

C++ is a programming language. It makes programs work! seriously, programs need to be told what to do, how to react to certain commands and criteria, C++ will allow them to do this.

Who uses C++?

C++ is used worldwide, it is not owned by anyone and is treated as an official modern language. Almost all applications you come into contact with e.g.. Windows, Office, Lotus, will be wrote in C++, in fact, its safe to say that over 90% of the worlds programs are wrote and based around the C language. If you know how to program in C, then you can program in any language as they all derived from C.

How long does it take to learn?

hmm, there is no answer for this question, as it is different for every person who takes on C++. If you are determined to learn it, and you have a lot of spare time, then in a few months you can have the basics, it will certainly not happen in a matter of days or weeks! For you to master the language inside and out, will take a matter of years, and experience.

 

What you need?

Which Compiler?

C++ is a compiled language, meaning the whole code for your application is read before executed. There has to be a piece of software that reads your program's code, and that is a compiler. The problem is, there are millions of them out there, some that are free and simple, others that cost £,500 and have loads of features. I would recommend buying a good one (you can download free ones but they are a bit useless). One company to look out for is Borland (http://www.borland.com). They offer the best compilers available in this world today, They offer lots of features that help new programmers lean how systems work, My advice is to make a small investment into some of there software such as C++ Builder 5 or something similar and you will get years of enjoyment with it!

Computer Specs

Many people think that compiling software takes huge super-computers the size of vans. This is only true for some software. For large companies creating large software, this applies. For the rest of us, almost any machine will do. I am still using an old 386 to compile 32-bit applications, its a slow process but the power is still there. Basically, You will however require hard disk space. Source code can take up stacks of room, and the compiler will make loads of temporary files during the make process. 

Other sources of Info

There's billions of sources of information out there related to C++. Many good books and loads of message boards on the net, I strongly suggest that you get some books and reference manuals for help and examples. Websites cant really help as much as books in my opinion because although the language changes a little, the main base of it has never changed, so the websites will just confuse you! However, borland.com do have some great help and loads of other goodies!

 

The Basics

A first look at C++

Ok then, here we go, I'm going to show you the simplest program you can write, then go through the program, I will only point out the common sections, i.e., the bits which appear in every program:

--------------------------------------------------------------------------------------------------------------------------------------

    // Example program 1. The do nothing program

    #include <iostream.h>

    int main()
    {

    print << "Hello world!\n";


    return 0;


    }

--------------------------------------------------------------------------------------------------------------------------------------

There we go! this program prints 'Hello world!' to the screen and then closes. That's it! Now lets go through it:

The first line is a comment. It is a part of the program that is there only for the programmer and does not affect the program. The comment in this program is the line beginning with '//'. The two forward slashes indicate to the compiler that it should ignore the following text and skip to the next line.

But what's the point if they are ignored I hear you say!?

Comments are one of the most helpful things in the C++ language, because some programs get quite complex, comments help the programmer (or anyone else that may read the code) understand what is written.

Ok, the next line '#include <iostream.h>'. This tell the compiler to include the following filename. In this case iostream.h. Iostream.h can simply be described as another mini program that is included in this program, it simply holds commands and information about functions in our program.

Now for the 'int main()' line. Every C++ program must have an this line, it tells the compiler that your program is starting now, the lines before simply pull all the resources together to compile it, but this line tells it we are going to start. This line is followed by an open brace '{' to show that the follow text is the body of the program.

Ok, guess what the following line does: 'print << "Hello world!\n";'. This line tells the compiler to print ( using the cout << statement) the following text to the screen.