Component type: type
struct ltstr {
bool operator()(const char* s1, const char* s2) const {
return strcmp(s1, s2) < 0;
}
};
int main() {
multimap<const char*, int, ltstr> m;
m.insert(pair<const char* const, int>('a', 1));
m.insert(pair<const char* const, int>('c', 2));
m.insert(pair<const char* const, int>('b', 3));
m.insert(pair<const char* const, int>('b', 4));
m.insert(pair<const char* const, int>('a', 5));
m.insert(pair<const char* const, int>('b', 6));
cout << 'Number of elements with key a: ' << m.count('a') << endl;
cout << 'Number of elements with key b: ' << m.count('b') << endl;
cout << 'Number of elements with key c: ' << m.count('c') << endl;
cout << 'Elements in m: ' << endl;
for (multimap<const char*, int, ltstr>::iterator it = m.begin(); it != m.end(); ++it)
cout << ' [' << (*it).first << ', ' << (*it).second << ']' << endl;
}
Defined in the standard header map, and in the nonstandard backward-compatibility header multimap.h.
| Parameter | Description | Default |
|---|---|---|
Key | The multimap's key type. This is also defined as | |
Data | The multimap's data type. This is also defined as | |
Compare | The key comparison function, a Strict Weak Ordering whose argument type is | less<Key> |
Alloc | The | alloc |
Multiple Sorted Associative Container, Pair Associative Container
None.
| Member | Where defined | Description |
|---|---|---|
key_type | Associative Container | The |
data_type | Pair Associative Container | The type of object associated with the keys. |
