🔴 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.
set stores unique sorted values. map stores key-value pairs and is useful for fast lookup.
Level
🔴 STL, Modern C++ and Projects
🔴 STL, Modern C++ and Projects
Example File
set-map.cppMain Focus
Concept + syntax + practical C++ program
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
| Term | Meaning / Use |
|---|---|
| set | set and map in STL programming में Set use होता है। |
| map | set and map in STL programming में Map use होता है। |
| key-value | Key-set and map in STL programming में value use होता है। |
| unique | set and map in STL programming में Unique use होता है। |
| lookup | set 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
- Count frequency of words using map.
- 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.
set stores unique sorted values. map stores key-value pairs and is useful for fast lookup.
Level
🔴 STL, Modern C++ and Projects
🔴 STL, Modern C++ and Projects
Example File
set-map.cppमुख्य फोकस
Concept + syntax + practical C++ program
Concept + syntax + practical C++ program
इसे क्यों सीखें?
- यह आपको सही और पढ़ने-योग्य C++ programs लिखने में मदद करता है।
- यह school practicals, projects और competitive programming में बार-बार use होता है।
- यह OOP, STL और data structures जैसे advanced topics की नींव बनाता है।
ज़रूरी Terms
| Term | अर्थ / उपयोग |
|---|---|
| set | Set set and map in STL programming में use होता है। |
| map | Map set and map in STL programming में use होता है। |
| key-value | Key-value set and map in STL programming में use होता है। |
| unique | Unique set and map in STL programming में use होता है। |
| lookup | Lookup 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)
- Count frequency of words using map.
- Store unique roll numbers using set.
सारांश
set and map in STL एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।
💻 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ें.