Answers for "loop thorugh map pairs cpp"

C++
1

cpp map iterate over keys

#include <iostream>
#include <map>

int main()
{
    std::map<std::string, int> myMap;

    myMap["one"] = 1;
    myMap["two"] = 2;
    myMap["three"] = 3;

    for ( const auto &myPair : myMap ) {
        std::cout << myPair.first << "n";
    }
}
Posted by: Guest on April-08-2021
0

How to loop through a set of pairs in c++

for (set<pair<int, int> >:: iterator it = a.begin(); it != a.end();/* blank */)
{
    cout << it->first << " " << it->second << endl;
    if (freq[it->first] == 1 || freq[it->second] == 1)
    {
        it = a.erase(it);
      	removed = true;
    }
    else
    {
        ++it;
    }
  
}
Posted by: Guest on November-28-2021

Browse Popular Code Answers by Language