I am attempting to add a vector to a position in a map according to a key.
vector<string> words;
map<string, vector<string>> wordMap;
for (int i = 0; i < words.size(); i++) {
string word = words.at(i);
if (wordMap.find(word) == wordMap.end())
wordMap.insert(make_pair(word, vector<string>()));
vector<string> context = { "EMPTY" };
if (i == 0)
context = { "Beginning of words", words[i + 1], words[i + 2] };
else if(i == 1)
context = { "Beginning of words", words[i - 1], words[i + 1], words[i + 2] };
else if (i == words.size() - 2)
context = { words[i - 2], words[i - 1], words[i + 1], "End of words" };
else if(i == words.size() - 1)
context = { words[i - 2], words[i - 1], "End of words" };
else
context = { words[i - 2], words[i - 1], words[i + 1], words[i + 2] };
wordMap[word].push_back(context);
cout << context[0] << endl;
}
I keep getting the following error at the period in
wordMap[word].push_back(context);
Error: no instance of overloaded function "std::vector<_Ty,_Alloc>::push_back[with_Ty=std::string,_Alloc=std::allocator<std::string>]" matches the argument list
argument types are: (std::vector<std::string, std::allocator<std::string>>)
object type is std::vector<std::string, std::allocator<std::string>>
Everything else in the program works and I can post it if you need me to, but the only error is when I try to use push_back. I need to use push_back because I cannot reassign the value. I have to keep all previous values located at that key, so push_back is ideal. Any help is greatly appreciated.