Example 1 — A subset
Check that 2 and 4 are inside a bigger list.
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> a = {1, 2, 3, 4, 5};
std::vector<int> b = {2, 4};
bool ok = std::includes(a.begin(), a.end(), b.begin(), b.end());
std::cout << std::boolalpha << "Contains all: " << ok << '\n';
return 0;
} How It Works
- Both vectors are sorted, which
includes()needs. - It walks through
aand finds 2, then 4. - Every value of
bwas found, so the result istrue.

