For some reason the compiler won't let me retrieve the vector of integers from the map that I've created, I want to be able to overwrite this vector with a new vector. The error the compiler gives me is ridiculous. Thanks for your help!!
The compiler didn't like this part of my code:
line_num = miss_words[word_1];
Error:
[Wawiti@localhost Lab2]$ g++ -g -Wall *.cpp -o lab2
main.cpp: In function ‘int main(int, char**)’:
main.cpp:156:49: error: no match for ‘operator=’ in ‘miss_words.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<std::basic_string<char>, std::vector<int>, std::less<std::basic_string<char> >, std::allocator<std::pair<const std::basic_string<char>, std::vector<int> > > >((*(const key_type*)(& word_1))) = line_num.std::vector<_Tp, _Alloc>::push_back<int, std::allocator<int> >((*(const value_type*)(& line)))’
main.cpp:156:49: note: candidate is:
In file included from /usr/lib/gcc/x86_64-redhat->linux/4.7.2/../../../../include/c++/4.7.2vector:70:0,
from header.h:19,
from main.cpp:15:
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/vector.tcc:161:5: note: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/vector.tcc:161:5: note: no known conversion for argument 1 from ‘void’ to ‘const std::vector<int>&’
CODE:
map<string, vector<int> > miss_words; // Creates a map for misspelled words
string word_1; // String for word;
string sentence; // To store each line;
vector<int> line_num; // To store line numbers
ifstream file; // Opens file to be spell checked
file.open(argv[2]);
int line = 1;
while(getline(file, sentence)) // Reads in file sentence by sentence
{
sentence=remove_punct(sentence); // Removes punctuation from sentence
stringstream pars_sentence; // Creates stringstream
pars_sentence << sentence; // Places sentence in a stringstream
while(pars_sentence >> word_1) // Picks apart sentence word by word
{
if(dictionary.find(word_1)==dictionary.end())
{
line_num = miss_words[word_1]; //Compiler doesn't like this
miss_words[word_1] = line_num.push_back(line);
}
}
line++; // Increments line marker
}