Iterators c++ In Hindi
C++ प्रोग्रामिंग लैंग्वेज में कंटेनर इटरेटर ऐसे यूजर डिफाइन प्रोगाम डाटा टाइप ऑब्जेक्ट होते हैं, जो C++ कंटेनर डाटा टाइप के एलिमेंट जैसे वेक्टर, लिस्ट, सेट, मैप, आदि डाटा एलिमेंट को एक्सेस मैनेज और ट्रैवर्स करने के कई मेथड और चॉइस प्रोवाइड करते हैं। ये पॉइंटर्स डाटा ऑब्जेक्ट के जैसे कार्य करते हैं, लेकिन उपयोग में ज़्यादा फ्लेक्सिबल और रिलाएबल होते हैं, और C++ प्रोग्राम में मल्टीप्ल इंडिविजुअल डाटा टाइप कंटेनर के साथ कई तरह से ये यूज़ किए जा सकते हैं। C++ कंटेनर डाटा टाइप में इटरेटर स्टैंडर्ड टेम्पलेट लाइब्रेरी (STL) का एक इम्पोर्टेन्ट फीचर्स हैं, और यह C++ यूजर को कंटेनर डाटा टाइप की स्पेशल फीचर्स को सेपरेट करने देते हैं. इसके साथ ही ये कंटेनर डाटा टाइप के डाटा एलिमेंट को एक्सेस और मॉडिफाई करने में भी हेल्प करते हैं।

Types of Container Data Type Iterators in C++ Programming.
C++ प्रोग्रामिंग हमें कई तरह के इटरेटर डाटा कंटेनर चॉइस प्रोवाइड करता है. जो कम्प्लीटली इस बात पर डिपेंड करता है कि किस तरह के ऑपरेशन इसके साथ परफॉर्म किए जा सकते हैं.
Input C++ Iterator.
- इनपुट C++ इटरेटर यूजर डिफाइन कंटेनर वेक्टर, लिस्ट, सेट, मैप, आदि डाटा टाइप से हमें डाटा और इनफार्मेशन को वन डायरेक्शन रीड करने में हेल्प करता है।
- जिसमे ++ (इंक्रीमेंट) और * (डीरेफरेंस) ऑपरेटर को यह सपोर्ट करता है।
Output C++ Iterator.
- आउटपुट C++ इटरेटर यूजर डिफाइन कंटेनर वेक्टर, लिस्ट, सेट, मैप, आदि डाटा टाइप में डाटा और इनफार्मेशन को वन डायरेक्शन में क्रिएट या राइट करने में हेल्प करता है।
- यह ++ (इंक्रीमेंट) और * (डीरेफरेंस) C++ प्रोग्राम ऑपरेटर को सपोर्ट करता है।
Forward C++ Iterator.
- यह C++ इटरेटर यूजर डिफाइन कंटेनर लिस्ट आदि डाटा टाइप में एक ही डायरेक्शन (फॉरवर्ड) में डाटा और इनफार्मेशन को रीड और राइट करने में हेल्प करता है।
- इसके साथ यह ++, *, और != आदि कंटेनर डाटा ऑपरेटर को भी सपोर्ट करता है।
Bidirectional C++ Iterator.
- यह C++ इटरेटर यूजर डिफाइन कंटेनर वेक्टर, लिस्ट, सेट, मैप, आदि डाटा टाइप में दोनों डायरेक्शन (फॉरवर्ड और बैकवर्ड) मूव करने में हेल्प करता है।
- इसके साथ यह कंटेनर में ++, –, *, और != ऑपरेटर को भी सपोर्ट करता है।
Random Access C++ Iterator.
- यह कंटेनर डाटा टाइप में किसी भी एलिमेंट को लगातार समय में डायरेक्ट एक्सेस करने में हेल्प करता है. जैसे ऐरे।
- अरिथमेटिक कंटेनर डाटा टाइप ऑपरेशन के लिए ++, –, *, !=, [], और + / – ऑपरेटर को भी ये सपोर्ट करता है।
- अधिकतर C++ STL कंटेनर डाटा टाइप में जैसे वेक्टर, डेक, मैप, सेट कंटेनर के आधार पर रैंडम एक्सेस इटरेटर या बाईडायरेक्शनल इटरेटर मेथड को सपोर्ट करते हैं।
Basic Container Data Type Operations with Iterators.
C++ कंटेनर डाटा टाइप में इटरेटर कई तरह के डाटा ऑपरेशन टास्क को सपोर्ट करते हैं. जो पॉइंटर डाटा टाइप से बहुत हद तक मिलते-जुलते होते हैं।
Some basic C++ container data types include iterator operations.
- Dereferencing (*iter) – यह उस कंटेनर डाटा एलिमेंट को एक्सेस करता है. जिस पर इटरेटर डाटा ऑब्जेक्ट पॉइंट करता है।
- Incrementing (++iter or iter++) – यह इटरेटर डाटा ऑब्जेक्ट को नेक्स्ट एलिमेंट पर मूव करता है।
- Comparison (iter != iter_end) – यह इटरेटर डाटा ऑब्जेक्ट की बराबरी या गैर-बराबरी को चेक करने के लिए इटरेटर की तुलना करता है।
- Arrow operator (iter->) – यह इटरेटर से पॉइंट किए गए डाटा ऑब्जेक्ट के मेंबर को एक्सेस करता है. जिसमे, यह मैप या सेट जैसे कंटेनर के लिए यूज़फुल है।
Using the iterator concept with container data types.
यहां आपको कुछ एक्साम्प्ल दिए गए हैं, जो किसी प्रोगाम में डिस्प्ले करते हैं कि अलग-अलग कंटेनर डाटा टाइप मेथड के साथ इटरेटर का कैसे यूज़ करें।
Iterator concept in C++ with vectors.
C++ प्रोग्रामिंग लैंग्वेज में वेक्टर एक सीक्वेंस कॉन्टिनियस डाटा टाइप कंटेनर मेथड है. जो रैंडम एक्सेस इटरेटर मेथड को सपोर्ट करता है, इसका मतलब है कि C++ यूजर इनका यूज़ किसी भी ऑर्डर में डाटा एलिमेंट को फास्टली ट्रैवर्स करने के लिए कर सकते हैं।
Example of iterator usage with the vector container data type.
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> vctr = {9, 23, 47, 59, 87, 98};
// here we declaring an iterator method for the vector data type element
vector<int>::iterator it = vctr.begin();
// here we accessing vector data type elements using iterators method
cout << “Here we use iterator method to traverse vector data element – “;
while (it != vctr.end()) {
cout << *it << ” “; // here we use dereferencing the iterator concept
++it; // here it incrementing the iterator value with ++ increment operator
}
cout << endl;
return 0;
}
Explanation of iterator usage with the vector container data type.
- यहाँ इस वेक्टर इटरेटर एक्साम्प्ल में vctr.begin() वेक्टर के फर्स्ट एलिमेंट की ओर इंडीकेट करते हुए एक इटरेटर वैल्यू को रिटर्न करता है।
- vctr.end() वेक्टर के अंत एलिमेंट के बाद इंडीकेट करते हुए एक इटरेटर वैल्यू को रिटर्न करता है।
- *यह वेक्टर डाटा टाइप कंटेनर वैल्यू को एक्सेस करने के लिए इटरेटर को डीरेफरेंस करता है।
- इन्क्रीमेंट ऑपरेटर ++ यह नेक्स्ट वेक्टर एलिमेंट पर मूव करने के लिए इटरेटर को इन्क्रीमेंट करता है।
List data type Iterator concept in C++.
C++ प्रोग्रामिंग लैंग्वेज में लिस्ट कंटेनर डाटा टाइप एक डबल लिंक्ड लिस्ट डाटा टाइप की तरह होती है, और यह बाईडायरेक्शनल इटरेटर मेथड को सपोर्ट करती है. जिससे C++ यूजर लिस्ट कंटेनर डाटा टाइप को फॉवर्ड और बैकवर्ड दोनों डायरेक्शन में व्यू और ऑपरेट कर सकते हैं।
Example of using a container iterator with a list.
#include <iostream>
#include <list>
using namespace std;
int main() {
list<int> lst = {712, 489, 987, 569, 789, 898};
// here we declaring an iterator for the list element
list<int>::iterator it = lst.begin();
// here we traversing the list in forwards direction
cout << “Iterator method to traverse list element in forward direction – “;
while (it != lst.end()) {
cout << *it << ” “;
++it;
}
cout << endl;
// here it traversing the list in backwards direction
cout << “Iterator method to traverse list element in backward direction – “;
list<int>::reverse_iterator rit = lst.rbegin(); // here it reverse iterator method
while (rit != lst.rend()) {
cout << *rit << ” “;
++rit;
}
cout << endl;
return 0;
}
Explanation of using a container iterator with a list.
- यहाँ लिस्ट इटरेटर एक्साम्प्ल में lst.begin() पहले लिस्ट एलिमेंट की ओर इंडीकेट करते हुए एक फॉरवर्ड इटरेटर प्रोवाइड करता है।
- यह लिस्ट में lst.end() लास्ट एलिमेंट के बाद का इटरेटर वैल्यू को प्रोवाइड करता है।
- lst.rbegin() लास्ट लिस्ट एलिमेंट की ओर इंडीकेट करते हुए एक रिवर्स इटरेटर प्रोवाइड करता है, जो बैकवर्ड डायरेक्शन की ओर जाने की परमिशन प्रोवाइड करता है।
- लिस्ट इटरेटर में ++it और ++rit इटरेटर को सीक्वेंस से फॉरवर्ड या बैकवर्ड मूव करने के लिए इनक्रीस करते हैं।
Set iterator concept in C++.
C++ प्रोग्रामिंग में सेट यूनिक डाटा एलिमेंट्स का एक ऑर्डर किया हुआ कलेक्शन ग्रुप डाटा टाइप कंटेनर होता है। यह C++ में बाईडायरेक्शनल इटरेटर मेथड को सपोर्ट करता है, जिससे सेट डाटा टाइप कंटेनर एलिमेंट में स्टार्ट से लास्ट तक सेट एलिमेंट डाटा टाइप को सॉर्टेड ऑर्डर में ट्रैवर्सल किया जा सकता है।
Example of using the iterator method with sets.
#include <iostream>
#include <set>
using namespace std;
int main() {
set<int> sat = {99, 66, 55, 77, 88, 99, 100};
// here we declaring an iterator for the set element container
set<int>::iterator it = sat.begin();
// here it traversing the set element
cout << “Iterator method to traverse list element set is – “;
while (it != sat.end()) {
cout << *it << ” “; // here it dereferencing the iterator method
++it; // here it incrementing the iterator method
}
cout << endl;
return 0;
}
Explanation of using the iterator method with sets.
- यहाँ इस एक्साम्प्ल में sat.begin() सेट के पहले (सबसे छोटे) एलिमेंट की ओर इंडीकेट करते हुए एक इटरेटर वैल्यू को प्रोवाइड करता है।
- sat.end() सेट एलिमेंट डाटा लास्ट एलिमेंट के बाद का एक इटरेटर वैल्यू को प्रोवाइड करता है।
- इसमें सेट डाटा टाइप नेचर के कारण सेट डाटा एलिमेंट अपने आप इनक्रीस आर्डर सीक्वेंस में सॉर्ट हो जाते हैं।
Map iterator concept in C++.
C++ प्रोग्रामिंग में मैप एक कंटेनर डाटा टाइप एलिमेंट है, जो की-वैल्यू पेयर आर्डर सीक्वेंस में डाटा और इनफार्मेशन को स्टोर करता है, और मैप डाटा टाइप के एलिमेंट अपने आप की के हिसाब से सीक्वेंस आर्डर में सॉर्ट हो कर अरेंज हो जाते हैं। मैप कंटेनर डाटा टाइप बाईडायरेक्शनल इटरेटर मेथड को सपोर्ट करता है।
Example of using an iterator with map container data.
#include <iostream>
#include <map>
using namespace std;
int main() {
map<string, int> mep = {{“c++”, 999}, {“Java”, 1099}, {“Matlab”, 1299}, {“Python”, 1199}};
// here we declaring an iterator for the map container data type
map<string, int>::iterator it = mep.begin();
// here it traversing the map container data type
cout << “Iterator method to traverse map stored element – “;
while (it != mep.end()) {
cout << it->first << ” –> ” << it->second << “, “;
++it;
}
cout << endl;
return 0;
}
Explanation of using an iterator with map container data.
- यहाँ मैप कंटेनर डाटा टाइप एक्साम्प्ल में it->first मैप डाटा एलिमेंट से की को एक्सेस करता है, और it->second मैप डाटा कंटेनर की-वैल्यू पेयर में वैल्यू को एक्सेस करता है।
- मैप डाटा टाइप इटरेटर ऑटोमैटिकली की के आधार पर सॉर्टेड ऑर्डर में मैप एलिमेंट को सीक्वेंस में ट्रैवर्स करते हैं।
Iterator method vectors, lists, sets, maps detail Summary.
| Iterator data Type | Detail Description | Operations Supported type |
| Input Iterator | It read container data elements in one direction | Use as ++, * dereferencing container operator |
| Output Iterator | It used to write container elements in one direction | It used as ++, * dereferencing container operator |
| Forward Iterator | It used to read and write container data elements in one direction | It used as ++, *, != comparison operator |
| Bidirectional Iterator | Here it read/write container data elements in both directions | It used as ++, –, *, != operator |
| Random Access Iterator | Here it supports all operations (like array access) | It used as ++, –, *, !=, [], +, – operator in container |

