Guide · C++ Programming Language

C++ Programming Language – Learning Guide

C++ builds on the C language: it adds classes, templates and a rich standard library (STL). It is the language most often used in informatics competitions, because it is fast and has ready-made data structures.

The lessons follow the order of learning: basics, loops, arrays and vectors, functions and strings, and then the STL.

  • Primary and secondary school
  • Competitions
  • Examples in C++
Tip: in competitions use vector, string and sort instead of hand-written arrays and sorting – the code is shorter and has fewer mistakes.

Some lessons linked below are available only in Serbian for now. They are marked (SR).

1 C++ basics

The first program, input and output (cin, cout), data types and operators.

2 Loops

Repeating statements and processing a sequence of input data.

3 Arrays, matrices and vectors

Static arrays, matrices and the dynamic array vector.

4 Functions, pointers and strings

Modular programming and working with text.

5 STL – the standard library

Ready-made data structures and algorithms that save time in competitions.

6 Object-oriented programming in C++

Classes and objects, inheritance and polymorphism in C++. The same concepts in Java are in the Java lessons.

7 Solved tasks in C++

Solved tasks, mostly from competitions, with explanations and code.

✎ A short example

Reading n numbers into a vector, sorting and printing them.

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;

    // reading n numbers into a vector
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    // sorting in ascending order
    sort(a.begin(), a.end());

    for (int x : a) cout << x << " ";
    cout << endl;
    return 0;
}