Friday 15 April 2011

c++ - Mysterious set iterator behavior -


If I compile and run the following program with the input of "4 petr egor", then "2 2 2" But hope that the output should be "2 1 2", if for some reason the statement from bottom to second if I get the output * Ier get "2", and if I output * charMap.begin () -> second Start (), I get "1" Why is this happening?

  #include & lt; Iostream & gt; # Include & lt; Vector & gt; #include & lt; String & gt; # Include & lt; Set & gt; # Include & lt; Map & gt; # Include & lt; Algorithm & gt; using namespace std; Int Hemingist (Const String and S, Constant Strings and T) {Int Count = 0; For (Int i = 0; I  second.size () == 1) {auto toRemove = removeIter; ++ removeIter; CharMap.erase (toRemove); to continue; } If (removeIter! = CharMap.end ()) ++ removeIter; } If (charMap.empty ()) {cout & lt; & Lt; Hummingstist (s, t) & lt; & Lt; Endl; Cout & lt; & Lt; "-1 -1"; } And if (charMap.size () == 1) {cout & lt; & Lt; Hemingdist (S, T) - 1 & lt; & Lt; Endl; Auto-id = charMap.begin () - & gt; Second. Bijin (); Cout & lt; & Lt; (* / * CharMap.begin () - & gt; seconds.bgin () * / iter) + 1 & lt; & Lt; '' & Lt; & Lt; (* (+++) + 1); // problem is here} and if (charMap.size ()> = 2) {cout & lt; & Lt; Hemingdist (S, T) - 2 & lt; & Lt; Endl; Auto-id = charMap.begin () - & gt; Second. Bijin (); Cout & lt; & Lt; ((* Eeter)) & lt; & Lt; '' & Lt; & Lt; (* (+++) + 1); }}  

This indicates that it enhances "Immer" first and then 2 Does its output Change it:

  Cot  

To do this:

  Cust & lt; & Lt; (* ENTER) + 1 & lt; & Lt; ''; ++ ITER; Cout & lt; & Lt; (* ENTER) + 1;  

If it was decided then it was a seat problem in all, not set Iterator.


No comments:

Post a Comment