std map in C++

#include <iostream>
#include <map>
using namespace std;

int main()
{

    map<int, char> m = {{1, 'A'}, {2, 'B'}, {3, 'C'}};
    for (auto el : m)
    {
        cout << el.first << ' ' << el.second << endl;
    }

    map<int, char> m2;
    m2[1] = 'D';
    m2[2] = 'E';
    m2[3] = 'F';
    m2.insert({10, 'G'});
    for (auto el2 : m2)
    {
        cout << el2.first << ' ' << el2.second << endl;
    }

    auto it = m2.find(10);
    if (it != m2.end())
    {
        cout << "Found :" << it->first << " " << it->second << endl;
    }

    return 0;
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *