Skip to content

Instantly share code, notes, and snippets.

@AndiH
Created August 21, 2014 13:08
Show Gist options
  • Select an option

  • Save AndiH/a9fa7e1126ea3768e7f1 to your computer and use it in GitHub Desktop.

Select an option

Save AndiH/a9fa7e1126ea3768e7f1 to your computer and use it in GitHub Desktop.
Small C++ multimap example
// Small example to show working with multimaps
// See cplusplus.com: http://www.cplusplus.com/reference/map/multimap/l
#include <map>
#include <iostream>
int main() {
std::multimap<int, double> mymultimap; // binid, multiplicity
mymultimap.insert(std::pair<int, double>(199, 20.1));
mymultimap.insert(std::pair<int, double>(1, 8.1));
mymultimap.insert(std::pair<int, double>(10, 2.54));
mymultimap.insert(std::pair<int, double>(1, 90.4));
for (std::multimap<int, double>::iterator it = mymultimap.begin(); it != mymultimap.end(); ++it) {
std::cout << (*it).first << " => " << (*it).second << std::endl;
}
std::multimap<int, double>::iterator itLow, itUp;
itLow = mymultimap.lower_bound(1);
itUp = mymultimap.upper_bound(1);
for (std::multimap<int, double>::iterator it = itLow; it != itUp; ++it) {
std::cout << (*it).first << " => " << (*it).second << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment