इस लेख में हम C++ STL में काम करने, वाक्य रचना और map::clear() फ़ंक्शन के उदाहरणों पर चर्चा करेंगे।
C++ STL में मैप क्या है?
मानचित्र सहयोगी कंटेनर हैं, जो एक विशिष्ट क्रम में कुंजी मान और मैप किए गए मान के संयोजन से बने तत्वों को संग्रहीत करने की सुविधा प्रदान करते हैं। मैप कंटेनर में डेटा को हमेशा उसकी संबद्ध कुंजियों की मदद से आंतरिक रूप से सॉर्ट किया जाता है। मानचित्र कंटेनर के मानों को इसकी विशिष्ट कुंजियों द्वारा एक्सेस किया जाता है।
नक्शा क्या है::clear()?
map::clear() फ़ंक्शन C++ STL में एक इनबिल्ट फ़ंक्शन है, जिसे
सिंटैक्स
Map_name.clear();
पैरामीटर
यह फ़ंक्शन कोई पैरामीटर स्वीकार नहीं करता है।
रिटर्न वैल्यू
यह फ़ंक्शन कुछ भी नहीं देता है
उदाहरण
इनपुट
map<char, int> newmap; newmap[‘a’] = 1; newmap[‘b’] = 2; newmap[‘c’] = 3; newmap.clear();
आउटपुट
size of the map is: 0
उदाहरण
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, string> TP_1, TP_2;
//Insert values
TP_1[1] = "Tutorials";
TP_1[2] = "Point";
TP_1[3] = "is an";
TP_1[4] = "education portal";
//size of map
cout<< "Map size before clear() function: \n";
cout << "Size of map1 = "<<TP_1.size() << endl;
cout << "Size of map2 = "<<TP_2.size() << endl;
//call clear() to delete the elements
TP_1.clear();
TP_2.clear();
//now print the size of maps
cout<< "Map size after applying clear() function: \n";
cout << "Size of map1 = "<<TP_1.size() << endl;
cout << "Size of map2 = "<<TP_2.size() << endl;
return 0;
} आउटपुट
Map size before clear() function: Size of map1 = 4 Size of map2 = 0 Map size after applying clear() function: Size of map1 = 0 Size of map2 = 0