I have a multimap and I want to save all of the unique keys in it in a vector.

```multimap<char,int> mymm;
multimap<char,int>::iterator it;
char c;

mymm.insert(pair<char,int>('x',50));
mymm.insert(pair<char,int>('y',100));
mymm.insert(pair<char,int>('y',150));
mymm.insert(pair<char,int>('y',200));
mymm.insert(pair<char,int>('z',250));
mymm.insert(pair<char,int>('z',300));```

How can I accomplish this?

There is a method for counting the number of items with a key, but none for counting the number of unique keys in a multimap.

Added: By unique, I mean all the keys in the multimap just once - they can be duplicated or appear only once in the multimap.

So unique keys here are - xy and z

Jun 22, 2022 in C++ 1,285 views

## 1 answer to this question.

This method worked for me.

```for( multimap<char,int>::iterator it = mymm.begin(), end = mymm.end(); it != end; it = mymm.upper_bound(it->first))

```  {
cout << it->first << ' ' << it->second << endl;
}``````
answered Jun 27, 2022 by
• 4,960 points

## How can I get the maximum or minimum value in a vector?

In C++, how can I find the greatest or minimum value in a vector? Is it correct to assume that it would be similar with an array? Do I require an iterator?  I tried max element, but I kept receiving errors. vector<int>::const_iterator it; it = max_element(cloud.begin(), cloud.end()); error: request for ...READ MORE

## How can I get the size of a C++ function?

In C++, how can I find the size& ...READ MORE

## How can I get double quotes into a string literal?

I used the printf() command to produce the output seen below: printf("She said time flies like an arrow, ...READ MORE

## How can I terminate an infinite loop in Turbo C?

I get caught in an infinite loop.  How can I break this cycle?  Cntrl-C was attempted, however it had little effect.  I have no idea how to stop it. main() { ...READ MORE

## How do I reverse a C++ vector?

The algorithm header has a method std::reverse for this purpose. #include <vector> #include <algorithm> int main() { std::vector<int> ...READ MORE

## How to expose std::pair to python using boost::python?

The most simple example of exposing std::pair is: class_<std::pair<int, int> ...READ MORE

## How to find out if an item is present in an std::vector?

The most straightforward solution is to count the total number of elements in the vector that have the specified value.  If the count is greater than zero, we've found our element.  This is simple to accomplish with the std::count function. #include <iostream> #include <vector> #include <algorithm> int main() { ...READ MORE

## Syntax of priority queue

We must first include the queue header file in order to establish a priority queue in C++. #include <queue> Once we import this file, we ...READ MORE