C++-এ Map এবং Unordered Map হ্যাশ টেবিল (hash table)। এগুলো কিছু কী (key) এবং তাদের রেসপেক্টিভ কী-ভ্যালু (key-value) ব্যবহার করে। এখানে আমরা দেখব কীভাবে চেক করা যায় একটি দেওয়া কী হ্যাশ টেবিলে আছে কিনা। কোড নিচের মতো:
উদাহরণ
#include<iostream> #include<map> using namespace std; string isPresent(map<string, int> m, string key) { if (m.find(key) == m.end()) return "Not Present"; return "Present"; } int main() { map<string, int> my_map; my_map["first"] = 4; my_map["second"] = 6; my_map["third"] = 6; string check1 = "fifth", check2 = "third"; cout << check1 << ": " << isPresent(my_map, check1) << endl; cout << check2 << ": " << isPresent(my_map, check2); }আউটপুট
fifth: Not Present third: Present