Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ STL Map - find(pair<string,bool>) works in windows Visual Studio but not with g++ in Linux!
    text
    copied!<p>I seem to be having issues with using find() with the STL map on different platforms. Here is my code to be complete:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; #include &lt;map&gt; using namespace std; void constructDictionary(map&lt;string,bool&gt; &amp;dict); bool isInDictionary(string word, map&lt;string,bool&gt; &amp;dict); int main(void) { map&lt;string, bool&gt; dictionary; constructDictionary(dictionary); map&lt;string, bool&gt;::iterator it = dictionary.begin(); while(it != dictionary.end()){ cout &lt;&lt; it-&gt;first &lt;&lt;endl; it++; } string word; while(true){ cout &lt;&lt; "Enter a word to look up: " &lt;&lt; endl; cin &gt;&gt; word; if(isInDictionary(word, dictionary)) cout &lt;&lt; word &lt;&lt; " exists in the dictionary." &lt;&lt; endl; else cout &lt;&lt; word &lt;&lt; " cannot be found in the dictionary." &lt;&lt; endl; } return 0; } void constructDictionary(map&lt;string,bool&gt; &amp;dict) { ifstream wordListFile; wordListFile.open("dictionaryList.txt"); string line; while(!wordListFile.eof()){ getline(wordListFile, line); dict.insert(pair&lt;string,bool&gt;(line, true)); } wordListFile.close(); } bool isInDictionary(string word, map&lt;string,bool&gt; &amp;dict) { if(dict.find(word) != dict.end()) return true; else return false; } </code></pre> <p><code>isInDictionary()</code> works fine if compiled using visual studio in windows, however, on ubuntu and g++, this only works for the last entry made into the map. Any other word that I query returns false. I don't understand the discrepancy in this behavior. In both cases, the while statement at the beginning of main correctly prints out everything in the map to prove that everything's there.</p> <p>Any ideas? Thank you.</p>
 

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