What will be printed as a result of the code execution? (C++11)
#include <iostream>
#include <map>
using namespace std;

int main()
    multimap<char, int> mm{{'a',1},{'b',2},{'c',3},{'a',4},{'a',5},{'c',1}};
    map<char, int> m(++mm.begin(), mm.lower_bound('c'));
    for(auto i: m)
    for(auto i: m)
        cout << i.second << ' ';
    return 0;
The elements in mm will be located by key in the initialization order: {'a', 1}, {'a', 4}, {'a', 5}, {'b', 2}, {'c', 3} , {'c', 1}}. Initialization of m starts from the second element and ends before the first element with the key 'c'. So m will contain {'a', 4} and {'b', 2}. In the first loop, the copy of m changes, that is, in the second loop, the unchanged source map will be displayed.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Зарегистрируйся сейчас
или Подпишись на будущие тесты