Note that there are some explanatory texts on larger screens.

plurals
  1. POMultimap erase doesn't work
    primarykey
    data
    text
    <p>following code doesn't work with input:</p> <pre><code>2 7 add Elly 0888424242 add Elly 0883666666 queryname Elly querynum 0883266642 querynum 0888424242 delnum 0883666666 queryname Elly 3 add Kriss 42 add Elly 42 querynum 42 </code></pre> <p>Why my erase doesn't work?</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;iostream&gt; #include&lt;map&gt; #include &lt;string&gt; using namespace std; void PrintMapName(multimap&lt;string, string&gt; pN, string s) { pair&lt;multimap&lt;string,string&gt;::iterator, multimap&lt;string,string&gt;::iterator&gt; ii; multimap&lt;string, string&gt;::iterator it; ii = pN.equal_range(s); multimap&lt;string, int&gt; tmp; for(it = ii.first; it != ii.second; ++it) { tmp.insert(pair&lt;string,int&gt;(it-&gt;second,1)); } multimap&lt;string, int&gt;::iterator i; bool flag = false; for(i = tmp.begin(); i != tmp.end(); i++) { if(flag) { cout&lt;&lt;" "; } cout&lt;&lt;i-&gt;first; if(flag) { cout&lt;&lt;" "; } flag = true; } cout&lt;&lt;endl; } void PrintMapNumber(multimap&lt;string, string&gt; pN, string s) { multimap&lt;string, string&gt;::iterator it; multimap&lt;string, int&gt; tmp; for(it = pN.begin(); it != pN.end(); it++ ) { if(it-&gt;second == s) { tmp.insert(pair&lt;string,int&gt;(it-&gt;first,1)); } } multimap&lt;string, int&gt;::iterator i; bool flag = false; for(i = tmp.begin(); i != tmp.end(); i++) { if(flag) { cout&lt;&lt;" "; } cout&lt;&lt;i-&gt;first; if(flag) { cout&lt;&lt;" "; } flag = true; } cout&lt;&lt;endl; } void PrintFull(multimap&lt;string, string&gt; pN) { multimap&lt;string, string&gt;::iterator it; for(it = pN.begin(); it != pN.end(); it++ ) { cout&lt;&lt;"Key = "&lt;&lt;it-&gt;first&lt;&lt;" Value = "&lt;&lt;it-&gt;second&lt;&lt;endl; } } int main() { multimap&lt;string, string&gt; phoneNums; int N; cin&gt;&gt;N; int tests; string tmp, tmp1,tmp2; while(N &gt; 0) { cin&gt;&gt;tests; while(tests &gt; 0) { cin&gt;&gt;tmp; if(tmp == "add") { cin&gt;&gt;tmp1&gt;&gt;tmp2; phoneNums.insert(pair&lt;string,string&gt;(tmp1,tmp2)); } else { if(tmp == "delnum") { /////////////////////////////////////////HEREEEEEEE multimap&lt;string, string&gt;::iterator it; multimap&lt;string, string&gt;::iterator tmpr; for(it = phoneNums.begin(); it != phoneNums.end();) { tmpr = it; if(it-&gt;second == tmp1) { ++tmpr; if(tmpr == phoneNums.end()) { phoneNums.erase(it,tmpr); break; } else { phoneNums.erase(it,tmpr); } } } } else { if(tmp == "delname") { cin&gt;&gt;tmp1; phoneNums.erase(tmp1); } else { if(tmp =="queryname") { cin&gt;&gt;tmp1; PrintMapName(phoneNums, tmp1); } else//querynum { cin&gt;&gt;tmp1; PrintMapNumber(phoneNums, tmp1); } } } } tests--; } N--; } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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