As we all know, map is designed based on a balanced binary tree. Therefore, whether it is directly written
For example
Map <string, string> str_map;
Str_map ["Alex"] = "Yes? ";
Str_map ["Alex"] = "No! ";
Then, the order in the map is
Alex-no!
Alex-yes?
Of course, this was what I realized.
The specific problem is that, I want to simplify it. Because you need to write a value in Buf, and then store it in Map <string, string>.
Sprintf (BUF, "instance-% d is OK", I + 1 );
ID _ = Buf;
Sprintf (BUF, "instance-% d is prepared", I + 1 );
If (str_map.find (ID _) = str_map.end () // If ID _ does not exist, add it
Str_map [ID _] = boost: lexical_cast <string> (BUF );
Then, the map will be written to the HTML file.
Result When instance> 9, the problem occurs.
Instance-1 is prepared
Instance-10 is prepared
Instance-11 is prepared
Instance-12 is prepared
Instance-2 is prepared
Instance-3 is prepared
Instance-4 is prepared
Instance-5 is prepared
Instance-6 is prepared
Instance-7 is prepared
Instance-8 is prepared
Instance-9 is prepared
If you have a better solution, please leave a message and share your thoughts.
My solution: how to sort strings in Map