map โ Key-Value Store
cpp
#include <iostream>
#include <map>
#include <set>
using namespace std;
int main() {
// map - sorted by key
map<string, int> marks;
marks["Gagan"] = 95;
marks["Priya"] = 88;
marks["Raj"] = 72;
cout << marks["Gagan"] << endl; // 95
for (auto& [name, mark] : marks) // structured binding (C++17)
cout << name << ": " << mark << endl;
// Check if key exists
if (marks.count("Priya")) cout << "Priya found
";
// set - unique sorted elements
set<int> s = {5, 3, 8, 3, 1, 5}; // duplicates removed
for (int x : s) cout << x << " "; // 1 3 5 8
return 0;
}