C++ language tutorial

24 downloads 211 Views 524KB Size Report
C++ language tutorial. The cplusplus.com tutorial. Complete C++ language tutorial. 1.4 (August 2003) q Introduction r Instructions for use. q 1. Basics of C++.
C++ language tutorial

The cplusplus.com tutorial Complete C++ language tutorial 1.4 (August 2003)













Introduction ❍ Instructions for use. 1. Basics of C++. ❍ Structure of a C++ program. ❍ Variables. Data types. Constants. ❍ Operators. ❍ Communication through console. 2. Control structures and Functions. ❍ Control Structures. ❍ Functions (I). ❍ Functions (II). 3. Advanced Data. ❍ Arrays. ❍ Strings of Characters. ❍ Pointers. ❍ Dynamic Memory. ❍ Structures. ❍ User defined data types. (typedef, union, enum) 4. Object-oriented Programming. ❍ Classes. Constructors and Destructors. Pointers to classes. ❍ Overloading Operators. this. Static members. ❍ Relationships between classes: friend. Inheritance. ❍ Virtual Members. Abstraction. Polymorphism. 5. Advanced concepts. ❍ Templates. ❍ Namespaces. ❍ Exception handling.

http://www.cplusplus.com/doc/tutorial/ (1 of 2)14-04-2004 18:34:44

C++ language tutorial

Advanced classes type-casting. (new cast and typeid operators) ❍ Preprocessor directives. 6. C++ Standard Library. ❍ Input/Output with files. Epilogue. ❍ The Author. ❍





NOTE: The examples included in this tutorial are complete applications that can be compiled with almost any C++ compiler. If you want more info on how to compile these programs check the document Compilation of Console Programs. Written by Juan Soulié for the C++ Resources Network (www.cplusplus.com). English revision: Mitchell Markin. © The C++ Resources Network, 2000-2001 - All rights reserved

Go back: documents section

http://www.cplusplus.com/doc/tutorial/ (2 of 2)14-04-2004 18:34:44

Begin Tutorial: Introduction - Instructions for use

C++ Tutorial: Introduction, Instructions for use.

Introduction

Instructions for use To whom is this tutorial directed? This tutorial is for those people who want to learn programming in C++ and do not necessarily have any previous knowledge of other programming languages. Of course any knowledge of other programming languages or any general computer skill can be useful to better understand this tutorial, although it is not essential. If you are familiar with C language you can take the first 3 parts of this tutorial (from 1.1 to 3.4) as a review, since they mainly explain the C part of C++. Part 4 describes object-oriented programming. Part 5 mostly describes the new features introduced by ANSI-C++ standard.

Structure of this tutorial The tutorial is divided in 6 parts and each part is in several different sections. You can access any section directly from the main index or begin the tutorial from any point and follow the links at the bottom of each section. Many sections include an additional page with specific examples that describe the use of the newly acquired knowledge in that chapter. It is recommended to read these examples and be able to understand each of the code lines that constitute it before passing to the next chapter. A good way to gain experience with a programming language is by modifying and adding new functionalities on your own to the example programs that you fully understand. Don't be scared to modify the examples provided with this tutorial. There are no reports of people whose computer has been destroyed due to that.

Compatibility Notes The ANSI-C++ standard accepted as an international standard is relatively recent. It was

http://www.cplusplus.com/doc/tutorial/tut0-1.html (1 of 2)14-04-2004 18:35:06

C++ Tutorial: Introduction, Instructions for use.

published in November 1997, nevertheless the C++ language exists from long ago (1980s). Therefore there are many compilers which do not support all the new capabilities included in ANSI-C++, specially those released prior to the publication of the standard. During this tutorial, the concepts that have been added by ANSI-C++ standard which are not included in most older C++ compilers are indicated by the following icon:

"; cin >> n; while (n>0) { cout 0) remains true. All the process in the program above can be interpreted according to the following script: beginning in main: ❍ ❍



❍ ❍

1. User assigns a value to n. 2. The while instruction checks if (n>0). At this point there are two possibilities: ■ true: execute statement (step 3,) ■ false: jump statement. The program follows in step 5.. 3. Execute statement: cout 0; n--) { cout