#Code:
#include<iostream> #include<map> using namespace std; int main() { /* Declare map */ mapitem; /* Map iterator */ map :: iterator p; /* Initialize map */ item["Eraser"] = 0.50; /* Insert data */ item.insert(pair ("Pen", 2.50)); item.insert(pair ("Book", 200.55)); item.insert(pair ("Pencil", 1.00)); item.insert(pair ("Ex-Book", 250.10)); string srch = "Book"; /* Search data */ p = item.find(srch); if(p != item.end()) cout << "Price of the " << srch << " is " << p->second << endl; else cout << "Item not found!" << endl; /* Erase data */ item.erase("Pencil"); cout << "Item Deleted!" << endl; /* Display all elements */ for (p = item.begin(); p != item.end(); p++) cout << "Item: " << p->first << "\t"<< "Price: " << p->second << endl; return 0; }
0 Comment:
Đăng nhận xét
Thank you for your comments!