The C++ Tutorial

Welcome to! is a totally free website devoted to teaching you to program in C++. Whether you’ve had any prior experience programming or not, the tutorials on this site will walk you through all the steps you’ll need to know in order to create and compile your programs. Becoming an expert programmer won’t happen overnight, but with a little patience, you’ll get there. And will show you the way.

Latest news: We’ve migrated and rebuilt the site from the ground up. If you find any strange issues or broken features, please let us know here.

Chapter 0 Introduction / Getting Started
0.1 Introduction to these tutorials
0.2 Introduction to programming languages
0.3 Introduction to C/C++
0.4 Introduction to development
0.5 Installing an Integrated Development Environment (IDE)
0.6 Compiling your first program
0.7 A few common C++ problems
Chapter 1 C++ Basics
1.1 Structure of a program
1.3 A first look at variables
1.3a New A first look at cout, cin, endl, the std namespace, and using statements
1.4 A first look at functions
1.4a A first look at function parameters
1.5 A first look at operators
1.6 Whitespace and basic formatting
1.7 Forward declarations
1.8 Programs with multiple files
1.9 Header files
1.10 A first look at the preprocessor
1.10a How to design your first programs
1.11 Comprehensive quiz
Chapter 2 Variables Part I
2.1 Basic addressing and variable declaration
2.2 Keywords and naming identifiers
2.3 Variable sizes and the sizeof operator
2.4 Integers
2.5 Floating point numbers
2.6 Boolean Values
2.7 Chars
2.8 Constants
2.9 Hungarian Notation
2.10 Comprehensive quiz
Chapter 3 Operators
3.1 Precedence and associativity
3.2 Arithmetic operators
3.3 Increment/decrement operators, and side effects
3.4 Sizeof, comma, and arithmetic if operators
3.5 Relational operators (comparisons)
3.6 Logical operators
3.7 Converting between binary and decimal
3.8 Bitwise operators
3.x Comprehensive quiz
Chapter 4 Variables Part II
4.1 Blocks (compound statements) and local variables
4.2 Global variables (and why they are evil)
4.3 File scope and the static keyword
4.4 Type conversion and casting
4.5 Enumerated types
4.6 Typedefs
4.7 Structs
Chapter 5 Control Flow
5.1 Control flow introduction
5.2 If statements
5.3 Switch statements
5.4 Goto statements
5.5 While statements
5.6 Do while statements
5.7 For statements
5.8 Break and continue
5.9 Random number generation
Chapter 6 Arrays, Strings, Pointers, and References
6.1 Arrays (Part I)
6.2 Arrays (Part II)
6.3 Arrays and loops
6.4 Sorting an array using selection sort
6.5 Multidimensional arrays
6.6 C-style strings and an introduction to std::string
6.7 Introduction to pointers
6.8 Pointers, arrays, and pointer arithmetic
6.9 Dynamic memory allocation with new and delete
6.10 Pointers and const
6.11 References
6.12 References vs pointers, and member selection
6.13 Void pointers
Chapter 7 Functions
7.1 Function parameters and arguments
7.2 Passing arguments by value
7.3 Passing arguments by reference
7.4 Passing arguments by address
7.4a Returning values by value, reference, and address
7.5 Inline functions
7.6 Function overloading
7.7 Default parameters
7.8 Function pointers
7.9 The stack and the heap
7.10 Recursion
7.11 Namespaces
7.12 Handling errors (assert, cerr, exit, and exceptions)
7.13 Command line arguments
7.14 Ellipses (and why to avoid them)
Chapter 8 Basic object-oriented programming
8.1 Welcome to object-oriented programming
8.2 Classes and class members
8.3 Public vs private access specifiers
8.4 Access functions and encapsulation
8.5 Constructors
8.6 Destructors
8.7 The hidden “this” pointer
8.8 Constructors (Part II)
8.9 Class code and header files
8.10 Const class objects and member functions
8.11 Static member variables
8.12 Static member functions
8.13 Friend functions and classes
8.14 Anonymous variables and objects
Chapter 9 Operator overloading
9.1 Introduction to operator overloading
9.2 Overloading the arithmetic operators
9.3 Overloading the I/O operators
9.4 Overloading the comparison operators
9.5 Overloading unary operators +, -, and !
9.6 Overloading operators using member functions
9.7 Overloading the increment and decrement operators
9.8 Overloading the subscript operator
9.9 Overloading the parenthesis operator
9.10 Overloading typecasts
9.11 The copy constructor and overloading the assignment operator
9.12 Shallow vs. deep copying
Chapter 10 Composition
10.1 Constructor initialization lists
10.2 Composition
10.3 Aggregation
10.4 Container classes
Chapter 11 Inheritance
11.1 Introduction to inheritance
11.2 Basic inheritance in C++
11.3 Order of construction of derived classes
11.4 Constructors and initialization of derived classes
11.5 Inheritance and access specifiers
11.6 Adding, changing, and hiding members in a derived class
11.7 Multiple inheritance
11.8 Virtual base classes
Chapter 12 Virtual Functions
12.1 Pointers and references to the base class of derived objects
12.2 Virtual functions
12.3 Virtual destructors, virtual assignment, and overriding virtualization
12.4 Early binding and late binding
12.5 The virtual table
12.6 Pure virtual functions, abstract base classes, and interface classes
Chapter 13 Input and output (I/O)
13.1 Input and output (I/O) streams
13.2 Input with istream
13.3 Output with ostream and ios
13.4 Stream classes for strings
13.5 Stream states and input validation
13.6 Basic file I/O
13.7 Random file I/O
Chapter 14 Templates
14.1 Function templates
14.2 Function template instances
14.3 Template classes
14.4 Expression parameters and template specialization
14.5 Class template specialization
14.6 Partial template specialization
Chapter 15 Exceptions
15.1 The need for exceptions
15.2 Basic exception handling
15.3 Exceptions, functions, and stack unwinding
15.4 Uncaught exceptions, catch-all handlers, and exception specifiers
15.5 Exceptions, classes, and inheritance
15.6 Exception dangers and downsides
Chapter 16 The Standard Template Library
16.1 The Standard Template Library (STL)
16.2 STL containers overview
16.3 STL iterators overview
16.4 STL algorithms overview
Chapter 17 std::string
17.1 std::string and std::wstring
17.2 std::string construction and destruction
17.3 std::string length and capacity
17.4 std::string character access and conversion to C-style arrays
17.5 std::string assignment and swapping
17.6 std::string appending
17.7 std::string inserting
Appendix A Miscellaneous Subjects
A.1 Static and dynamic libraries
A.2 Using libraries with Visual Studio Express 2005
A.3 Using libraries with Code::Blocks
A.4 Debugging your program (stepping and breakpoints)
A.5 Debugging your program (watching variables and the call stack)
A.6 Fixed-width integers
Appendix B C++11 (Formerly C++0x)
B.1 Introduction to C++11
B.2 Long long, auto, decltype, nullptr, and enum classes
B.3 Range-based for statements and static_assert
B.4 Initializer lists and uniform initialization
B.5 Delegating constructors
B.6 New virtual function controls (override, final, default, and delete)

We are still adding content, so check back regularly! — Teaching you how to program in C++ since May 25, 2007.