Looping through nested map structure in C++

Photo by Vanessa on Unsplash

Looping through nested map structure in C++

Simple way to loop through the nested map structures.

 map<int, map<int, int> > u;
  u [2][3] = 25;
  u [4][5] = 65;

  if(auto it = u.find(4); it != u.end())
  {
    auto second_part = u[it->first];
    if(auto it1 = second_part.find(5); it1 != second_part.end())
    {
      cout<<it->first<<","<<it1->first<<","<<it1->second<<'\n';
      assert(it1->second==65);
    }
  }