Skip to content

Instantly share code, notes, and snippets.

@NigoroJr
Created December 30, 2014 06:57
Show Gist options
  • Save NigoroJr/a8c6450ce1d512f2c8d6 to your computer and use it in GitHub Desktop.
Save NigoroJr/a8c6450ce1d512f2c8d6 to your computer and use it in GitHub Desktop.
Sample program for using maps and iterating through them.
#include <iostream>
#include <map>
#include <string>
#include <iterator>
#include <boost/foreach.hpp>
#include <utility>
typedef Pair std::pair<std::string, int>
int main() {
std::map<std::string, int> m;
m["foo"] = 1;
m["bar"] = 3;
m["baz"] = 5;
std::map<std::string, int>::value_type&
// for (std::map<std::string, int>::iterator it = m.begin(); it != m.end(); it++) {
// std::cout << it->first << " " << it->second << std::endl;
// }
BOOST_FOREACH(Pair p : m) {
std::cout << p.first << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment