🔴 Advanced  ·  Lesson 57

set and map in STL

set and map in STL

What is set and map in STL?

set and map in STL
set stores unique sorted values. map stores key-value pairs and is useful for fast lookup.
Level
🔴 STL, Modern C++ and Projects
Example File
set-map.cpp
Main Focus
Concept + syntax + practical C++ program

Why should you learn this?

  • It helps you write correct and readable C++ programs.
  • It is used repeatedly in school practicals, projects and competitive programming.
  • It builds the base for advanced topics such as OOP, STL and data structures.

Important Terms

TermMeaning / Use
setset and map in STL programming में Set use होता है।
mapset and map in STL programming में Map use होता है।
key-valueKey-set and map in STL programming में value use होता है।
uniqueset and map in STL programming में Unique use होता है।
lookupset and map in STL programming में Lookup use होता है।

Syntax / Pattern

C++
map<Key,Value> m; m[key] = value;

Example Program

main.cpp
#include <iostream>
#include <map>
using namespace std;
int main(){
    map<string,int> marks;
    marks["Aman"] = 92;
    cout << marks["Aman"];
}

Expected Output

92

Program Explanation

  • Aman is the key.
  • 92 is the value associated with the key.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.

Where will you use it?

  • student marks
  • word frequency
  • configuration data

Common Mistakes

  • Using map when duplicate keys are required.
  • Forgetting that set stores unique values.

Practice Tasks

  1. Count frequency of words using map.
  2. Store unique roll numbers using set.

Summary

set and map in STL एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।

set and map in STL क्या है?

set and map in STL
set stores unique sorted values. map stores key-value pairs and is useful for fast lookup.
Level
🔴 STL, Modern C++ and Projects
Example File
set-map.cpp
मुख्य फोकस
Concept + syntax + practical C++ program

इसे क्यों सीखें?

  • यह आपको सही और पढ़ने-योग्य C++ programs लिखने में मदद करता है।
  • यह school practicals, projects और competitive programming में बार-बार use होता है।
  • यह OOP, STL और data structures जैसे advanced topics की नींव बनाता है।

ज़रूरी Terms

Termअर्थ / उपयोग
setSet set and map in STL programming में use होता है।
mapMap set and map in STL programming में use होता है।
key-valueKey-value set and map in STL programming में use होता है।
uniqueUnique set and map in STL programming में use होता है।
lookupLookup set and map in STL programming में use होता है।

Syntax / Pattern

C++
map<Key,Value> m; m[key] = value;

Example Program

main.cpp
#include <iostream>
#include <map>
using namespace std;
int main(){
    map<string,int> marks;
    marks["Aman"] = 92;
    cout << marks["Aman"];
}

Expected Output

92

Program Explanation

  • Aman is the key.
  • 92 is the value associated with the key.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.

Where will you use it?

  • student marks
  • word frequency
  • configuration data

आम गलतियाँ (Common Mistakes)

  • Using map when duplicate keys are required.
  • Forgetting that set stores unique values.

अभ्यास (Practice Tasks)

  1. Count frequency of words using map.
  2. Store unique roll numbers using set.

सारांश

set and map in STL एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।

← Back to C++ Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n

💻 Live Code Editor

Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें. Agar load na ho to naye tab mein kholें.