How can I insert elements into a multimap?

andre de boer picture andre de boer · Jan 26, 2013 · Viewed 17.1k times · Source

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

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

But how can I insert data into it? I tried the following code, but it doesn't compile:

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

Answer

harpun picture harpun · Jan 26, 2013

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));