Programming paths / C++

C++ learning path

Learn modern C++ with value types, standard containers, resource ownership, and clear error handling.

Starter lesson

Filter data with standard algorithms

The standard library lets you express common operations directly. This small example stores values in a vector and selects the ones that meet a rule.

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

int main() {
    const std::vector<int> scores{42, 87, 65, 91};
    std::vector<int> passing;

    std::copy_if(scores.begin(), scores.end(),
                 std::back_inserter(passing),
                 [](int score) { return score >= 70; });

    for (int score : passing) {
        std::cout << score << '\n';
    }
}

What to expect

87 91

Key idea: Prefer standard containers and algorithms before writing custom loops or managing raw memory.

← Browse all programming paths