RockAndaHardPlace RockAndaHardPlace - 1 year ago 115
C++ Question

c++ - Inserting 3 variable values into a multimap

I'm new to the use of maps and multimaps, and I'm having trouble (compiler errors and warnings) when trying to insert 3 values into a multimap via the use of a pair of strings (acting as the key) and an int value:

This is my multimap declaration:

multimap<pair<string, string>, int> wordpairs;

This is how I'm trying to populate the multimap:

int toInsert = 0;

for (int i = 0; i < s; i++) {

wordpairs.insert((words[i], words[i+1]), toInsert);


where words is:

vector<string> words

I'm getting this error and a bunch of warnings:

error: no matching function for call to ‘std::multimap<std::pair<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >, int>::insert(std::__cxx11::basic_string<char>&, int&)’
wordpairs.insert((words[i], words[i+1]), toInsert);

Not sure how to properly insert the values I want to. :(

Answer Source

You should use this wordpairs.insert( make_pair(make_pair(words[i], words[i+1]), toInsert));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download