intro.cpp 677 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2006-2009 Daniel James.
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. //[intro_example1_1
  5. #include <boost/unordered_map.hpp>
  6. #include <boost/foreach.hpp>
  7. #include <cassert>
  8. #include <iostream>
  9. //]
  10. int main() {
  11. //[intro_example1_2
  12. typedef boost::unordered_map<std::string, int> map;
  13. map x;
  14. x["one"] = 1;
  15. x["two"] = 2;
  16. x["three"] = 3;
  17. assert(x.at("one") == 1);
  18. assert(x.find("missing") == x.end());
  19. //]
  20. //[intro_example1_3
  21. BOOST_FOREACH(map::value_type i, x) {
  22. std::cout<<i.first<<","<<i.second<<"\n";
  23. }
  24. //]
  25. }