andre de boer andre de boer - 19 days ago 10
C++ Question

C++ how to insert in multimap?

I want to set up a multimap in C++:

multimap<pair<string, string>, vector<double> > mmList;


But how to insert data:

mmList.insert(pair<string, string>, vector<double>("a", "b", test));

Answer

You can construct pairs using std::make_pair(a, b). Generally you can insert pairs into maps/multimaps. In your case you have to construct a pair consisting of the string pair and the vector:

    std::multimap<std::pair<std::string, std::string>, std::vector<double> > mmList;

    std::vector<double> vec;
    mmList.insert(std::make_pair(std::make_pair("a","b"), vec));
Comments