07.08.2008, 14:53 | #13 |
MCT
|
Цитата:
Сообщение от kashperuk
Поправочка (спасибо mbelugin)
Map реализован как C++ container: http://en.wikipedia.org/wiki/Map_(C%2B%2B_container) То есть что то типа этого? X++: #include <iostream> #include <map> using namespace std; int main() { typedef map<char, int> mapType; mapType myMap; // insert elements using insert function myMap.insert(pair<char, int>('a', 1)); myMap.insert(pair<char, int>('b', 2)); myMap.insert(pair<char, int>('c', 3)); myMap.insert(pair<char, int>('d', 4)); myMap.insert(pair<char, int>('e', 5)); // erase the first element using the erase function mapType::iterator iter = myMap.begin(); myMap.erase(iter); // output the size of the map cout << "Size of myMap: " << myMap.size() << endl; cout << "Enter a key to search for: "; char c; cin >> c; // find will return an iterator to the matching element if it is found // or to the end of the map if the key is not found iter = myMap.find(c); if( iter != myMap.end() ) cout << "Value is: " << iter->second << endl; else cout << "Key is not in myMap" << endl; // clear the entries in the map myMap.clear(); } |
|
|
|