fork download
  1. #include <iostream>
  2. #include<map>
  3. #include<iterator>
  4. using namespace std;
  5.  
  6. void printMap(auto/*map<string,int>*/ fm){
  7. cout << fm.size() << endl;
  8. //map<string,int>::iterator it;
  9. for(auto it = fm.begin();it != fm.end();++it){
  10. //cout << (*it).first << "-" << (*it).second << endl;
  11. cout << it->first << "-" << it->second << endl;
  12. }
  13. }
  14. int main() {
  15. //basic initialization.
  16. map<string,int> m1;
  17. m1["date"] = 22;
  18. m1["month"] = 05;
  19. m1["year"] = 2004;
  20. printMap(m1);
  21.  
  22. //initializing a map using pair,using insert():
  23. map<string,int> m2;
  24. m2.insert(make_pair("date",22));
  25. m2.insert({"month",05});
  26. printMap(m2);
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5264KB
stdin
Standard input is empty
stdout
3
date-22
month-5
year-2004
2
date-22
month-5