Created
December 30, 2014 06:57
-
-
Save NigoroJr/a8c6450ce1d512f2c8d6 to your computer and use it in GitHub Desktop.
Sample program for using maps and iterating through them.
This file contains 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
#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