• Tutorials
  • Courses
  • Tracks

unordered map Question 5

Last Updated :
Discuss
Comments

#include <bits/stdc++.h>

using namespace std;


int main() {

unordered_map<string, int> mp;

mp["abc"] = 1;

mp["xy"] = 2;

mp["pqr"] = 3;

auto it = mp.find("xy");

it++;

if(it != mp.end())

cout << it->first << " " << it->second;

return 0;

}

C++
#include <bits/stdc++.h>
using namespace std;

int main()
{
    unordered_map<string, int> mp;
    mp["abc"] = 1;
    mp["xy"] = 2;
    mp["pqr"] = 3;
    auto it = mp.find("xy");
    it++;
    if (it != mp.end())
        cout << it->first << " " << it->second;
    return 0;
}


print any pair of map except ("xy", 2) this pair.

3 pqr

Garvage values

Error

Share your thoughts in the comments