Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with erasing elements from the set
    text
    copied!<p>I am having troubles with erasing elements from sets. I get <code>BUILD FAILED</code> from:</p> <pre><code>n2Ar.erase(it); n3Ar.erase(it); </code></pre> <p>where <code>it</code> is a pointer received from <code>find()</code> function: e.g. <code>it = n2Ar.find(*i);</code></p> <p>The whole listing of the program:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;set&gt; #include &lt;algorithm&gt; using namespace std; #define TESTING_FILE_IN //#define TESTING_FILE_OUT //#define DEBUG //#define SHOW_TIMING int outputSet(int i) { cout &lt;&lt; i &lt;&lt; endl; } /* * */ int main() { int n1, n2, n3; set&lt;int&gt; list, n1Ar, n2Ar, n3Ar; set&lt;int&gt;::iterator it; scanf("%d", &amp;n1); scanf("%d", &amp;n2); scanf("%d", &amp;n3); int val = 0; // Getting lists of voters for (unsigned i = 0; i &lt; n1; i++) { cin &gt;&gt; val; n1Ar.insert(val); } for (unsigned i = 0; i &lt; n2; i++) { cin &gt;&gt; val; n2Ar.insert(val); } for (unsigned i = 0; i &lt; n3; i++) { cin &gt;&gt; val; n3Ar.insert(val); } // Processing lists for (set&lt;int&gt;::iterator i = n1Ar.begin(); i != n1Ar.end(); ++i) { it = n2Ar.find(*i); if (it != n2Ar.end()) { list.insert(*i); n1Ar.erase(i); n2Ar.erase(it); } else { it = n3Ar.find(*i); if (it != n3Ar.end()) { list.insert(*i); n1Ar.erase(i); n3Ar.erase(it); } } } // Outputting the final list cout &lt;&lt; list.size() &lt;&lt; endl; for_each(list.begin(), list.end(), outputSet); return 0; } </code></pre> <p>I hope you'll be able to help me understand what I am doing wrong in here. I am only starting with C++.</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