R
Rishtaara
C++ Fundamentals
Lesson 3 of 8Article18 min

STL Containers and Iteration

STL Containers and Iteration

Most-used STL containers

  • vector for dynamic arrays.
  • map for key-value associations.
  • set for unique ordered values.
  • unordered_map for fast hash-based lookup.

Working with vector and map

STL basics
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
    vector<int> scores = {80, 92, 88};
    scores.push_back(95);

    map<string, int> marks;
    marks["Asha"] = 91;
    marks["Rohan"] = 85;

    for (int score : scores) cout << score << " ";
    cout << endl << marks["Asha"] << endl;
}