Показать сообщение отдельно
Старый 07.08.2008, 14:53   #12  
MikeR is offline
MikeR
MCT
Аватар для MikeR
MCBMSS
Лучший по профессии 2015
Лучший по профессии 2014
 
1,628 / 627 (24) +++++++
Регистрация: 28.11.2005
Адрес: просто землянин
Цитата:
Сообщение от 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();
}