Created
August 21, 2014 13:08
-
-
Save AndiH/a9fa7e1126ea3768e7f1 to your computer and use it in GitHub Desktop.
Small C++ multimap example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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