fork download
  1. #include <map>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. vector<int> keys = {0, 1};
  10.  
  11. map<int, int> m;
  12. m[1] = 5;
  13. m[2] = 12;
  14.  
  15. for (const int i : keys)
  16. {
  17. m[i]; // touch value
  18. }
  19.  
  20. for (auto const & kv : m)
  21. {
  22. cout << kv.first << ", " << kv.second << endl;
  23. }
  24. }
  25.  
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
0, 0
1, 5
2, 12