C++ Tutorial
C++ is a fast, powerful language used for games (Unreal Engine), web browsers (Chrome), apps like Photoshop, robotics, Arduino projects and competitive programming. It builds on C and adds classes, safer strings, resizable vectors and a huge library of ready-made tools.
This free course has 17 lessons. Every example is a complete program with its exact output, followed by a Taglish summary and a quick quiz.
How to run the examples
- On a computer: install a C++ compiler such as g++ (Code::Blocks with MinGW, or MSYS2 on Windows) or Clang (Mac). Lesson 2 shows how.
- On a phone: use an online C++ compiler.
Before you start
No experience is needed. If you've taken our C course, you already know most of the basic syntax and can move quickly through the first lessons.
What you'll be able to do
- Read input with
cinand print withcout - Use
std::stringandstd::vectorinstead of raw arrays - Write functions with references, overloading and default arguments
- Design classes with constructors, encapsulation, inheritance and polymorphism
- Use the STL: maps, sets, sorting and algorithms
- Build a complete inventory system
All lessons
Getting Started
- Introduction to C++What C++ is, how it grew from C, where it's used, what makes it powerful, and the parts of a first C++ program with cout.
- Getting Started with C++ — Install a Compiler and Run CodeInstall g++ or Clang, compile and run a C++ program from the command line, choose an IDE such as Code::Blocks, VS Code or Visual Studio, and read compiler errors.
- C++ Input and Output — cout, cin and getlinePrint values with cout and the << operator, read input with cin and >>, read full lines with getline, format decimals with fixed and setprecision, and align columns with setw.
Basics
- C++ Variables, Data Types, auto and constDeclare C++ variables with int, double, char, bool and string, use auto for type deduction, const and constexpr for constants, brace initialization and casting with static_cast.
- C++ Operators and the cmath LibraryArithmetic, assignment, comparison and logical operators in C++, increment and decrement, plus sqrt, pow, abs, round and other functions from cmath.
- C++ Strings — std::stringWork with text using std::string — join with +, compare with ==, get length, access characters, substr, find, replace, insert, erase, and convert between strings and numbers.
Control Flow
- C++ if, else, switch and the Ternary OperatorMake decisions in C++ with if, else if, else, switch-case and the ternary operator, including if with an initializer and switch on characters.
- C++ Loops — for, range-based for, while and do-whileRepeat code in C++ with for, range-based for, while and do-while loops, use break and continue, validate input with a loop, and build nested-loop patterns.
Functions & Data
- C++ Functions — Overloading, Default Arguments and ReferencesWrite C++ functions with parameters and return values, overload them, give parameters default values, pass by reference to change variables, and use recursion.
- C++ Arrays and VectorsStore lists in C++ with fixed arrays and resizable std::vector — push_back, size, at, insert, erase, 2D vectors, and passing vectors to functions.
- C++ References, Pointers and Smart PointersUnderstand references as aliases, pointers as addresses, the difference between them, dynamic memory with new and delete, and modern smart pointers like unique_ptr.
Object-Oriented Programming
- C++ Classes and ObjectsDefine classes with member variables and member functions, create objects, use public and private, write const member functions, and split a class into .h and .cpp files.
- C++ Constructors, Destructors and EncapsulationInitialize objects with constructors and member initializer lists, overload constructors, clean up with destructors, use getters and setters, and add static members.
- C++ Inheritance and PolymorphismDerive classes with public inheritance, call base constructors, override virtual functions, use polymorphism through base pointers and references, and create abstract classes.
The Standard Library
- C++ STL — map, set, sort and AlgorithmsUse the Standard Template Library — map and unordered_map for lookups, set for unique items, pair, sort with custom rules, find, count, accumulate and other algorithms.
- C++ File Streams and ExceptionsRead and write files with ofstream, ifstream and getline, parse CSV lines with stringstream, and handle errors with try, catch, throw and standard exceptions.
- C++ Final Project — Store Inventory SystemBuild a complete C++ inventory system with a Product class, vector and map, a menu, input validation, sorting with lambdas, low-stock alerts and CSV saving and loading.