cpp-programming

Simple C++ programs
git clone git://git.laack.co/cpp-programming.git
Log | Files | Refs | README

map-iterator.cpp (610B)


      1 #include <map>
      2 #include <string>
      3 #include <iostream>
      4 
      5 int main() {
      6     
      7     std::map<std::string,std::string> m;
      8 
      9     m["1"] = "Andrew";
     10     m["2"] = "Person";
     11     m["3"] = "Human";
     12 
     13     // this is much better than
     14     std::cout << "Auto" << std::endl;
     15     for (auto it = m.begin(); it != m.end(); ++it) {
     16         std::cout << it->first << " " << it->second << std::endl;
     17     }
     18 
     19     std::cout << "Explicit" << std::endl;
     20     for (std::map<std::string, std::string>::const_iterator it = m.begin(); it != m.end(); ++it) {
     21         std::cout << it->first << " " << it->second << std::endl;
     22     }
     23 
     24     return 0;
     25 
     26 }