🔴 Advanced · Lesson 58
Iterators in STL
Iterators in STL
What is Iterators in STL?
Iterators in STL
Iterators act like pointers to traverse STL containers. They provide a common way to move through vectors, sets, maps and other containers.
Iterators act like pointers to traverse STL containers. They provide a common way to move through vectors, sets, maps and other containers.
Level
🔴 STL, Modern C++ and Projects
🔴 STL, Modern C++ and Projects
Example File
iterators.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 |
|---|---|
| iterator | Iterators in STL programming में Iterator use होता है। |
| begin | Iterators in STL programming में Begin use होता है। |
| end | Iterators in STL programming में End use होता है। |
| dereference | Iterators in STL programming में Dereference use होता है। |
| traversal | Iterators in STL programming में Traversal use होता है। |
Syntax / Pattern
C++
for(auto it = v.begin(); it != v.end(); ++it)
Example Program
main.cpp
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> v = {5,10,15};
for(auto it = v.begin(); it != v.end(); ++it)
cout << *it << " ";
}Expected Output
5 10 15
Program Explanation
- begin() points to first element.
- end() points after last element.
- *it gives current value.
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?
- STL traversal
- algorithms
- generic programming
Common Mistakes
- Dereferencing end() iterator.
- Modifying container while using invalidated iterator.
Practice Tasks
- Traverse map using iterator.
- Explain begin() and end().
Summary
Iterators in STL एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।
Iterators in STL क्या है?
Iterators in STL
Iterators act like pointers to traverse STL containers. They provide a common way to move through vectors, sets, maps and other containers.
Iterators act like pointers to traverse STL containers. They provide a common way to move through vectors, sets, maps and other containers.
Level
🔴 STL, Modern C++ and Projects
🔴 STL, Modern C++ and Projects
Example File
iterators.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 | अर्थ / उपयोग |
|---|---|
| iterator | Iterator Iterators in STL programming में use होता है। |
| begin | Begin Iterators in STL programming में use होता है। |
| end | End Iterators in STL programming में use होता है। |
| dereference | Dereference Iterators in STL programming में use होता है। |
| traversal | Traversal Iterators in STL programming में use होता है। |
Syntax / Pattern
C++
for(auto it = v.begin(); it != v.end(); ++it)
Example Program
main.cpp
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> v = {5,10,15};
for(auto it = v.begin(); it != v.end(); ++it)
cout << *it << " ";
}Expected Output
5 10 15
Program Explanation
- begin() points to first element.
- end() points after last element.
- *it gives current value.
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?
- STL traversal
- algorithms
- generic programming
आम गलतियाँ (Common Mistakes)
- Dereferencing end() iterator.
- Modifying container while using invalidated iterator.
अभ्यास (Practice Tasks)
- Traverse map using iterator.
- Explain begin() and end().
सारांश
Iterators 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ें.