Note that there are some explanatory texts on larger screens.

plurals
  1. POMaps with a nested vector
    text
    copied!<p>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!!</p> <p>The compiler didn't like this part of my code:</p> <pre><code>line_num = miss_words[word_1]; </code></pre> <p>Error: </p> <pre><code>[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&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator[]&lt;std::basic_string&lt;char&gt;, std::vector&lt;int&gt;, std::less&lt;std::basic_string&lt;char&gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char&gt;, std::vector&lt;int&gt; &gt; &gt; &gt;((*(const key_type*)(&amp; word_1))) = line_num.std::vector&lt;_Tp, _Alloc&gt;::push_back&lt;int, std::allocator&lt;int&gt; &gt;((*(const value_type*)(&amp; line)))’ main.cpp:156:49: note: candidate is: In file included from /usr/lib/gcc/x86_64-redhat-&gt;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&lt;_Tp, _Alloc&gt;&amp; std::vector&lt;_Tp, _Alloc&gt;::operator=(const std::vector&lt;_Tp, _Alloc&gt;&amp;) [with _Tp = int; _Alloc = std::allocator&lt;int&gt;] /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&lt;int&gt;&amp;’ </code></pre> <p>CODE:</p> <pre><code>map&lt;string, vector&lt;int&gt; &gt; miss_words; // Creates a map for misspelled words string word_1; // String for word; string sentence; // To store each line; vector&lt;int&gt; 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 &lt;&lt; sentence; // Places sentence in a stringstream while(pars_sentence &gt;&gt; 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 } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload