⚡C++IntermediateLesson 35 of 50CamboFreelanceJune 19, 2026
C++ STL Introduction
Introduction to the C++ Standard Template Library (STL): containers, algorithms, and iterators. Learn sort, find, and accumulate.
Intermediate7 min readLesson 35 of 50
What is the STL?
The Standard Template Library (STL) is a powerful set of ready-to-use C++ template classes and functions. It provides generic containers, algorithms, and iterators.
Component
Description
Examples
Containers
Store collections of data
vector, map, set, queue, stack
Algorithms
Common operations on containers
sort, find, count, transform
Iterators
Navigate through containers
begin(), end(), rbegin()
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> nums = {5, 3, 8, 1, 9, 2};
sort(nums.begin(), nums.end());
for (int n : nums) cout << n << " ";
cout << endl;
auto it = find(nums.begin(), nums.end(), 8);
if (it != nums.end())
cout << "Found 8 at position " << (it - nums.begin()) << endl;
cout << "Count of 3: " << count(nums.begin(), nums.end(), 3) << endl;
return 0;
}
Output:
1 2 3 5 8 9
Found 8 at position 4
Count of 3: 1
Common STL Algorithms
Algorithm
Description
sort()
Sort a range
find()
Find first element matching value
count()
Count occurrences
reverse()
Reverse a range
max_element()
Find the maximum element
min_element()
Find the minimum element
accumulate()
Sum all elements (<numeric>)
Exercise
Create a vector of 10 integers. Use STL algorithms to: sort it, find the max and min, and calculate the sum.