大家都知道map内部是按照平衡二叉树来设计的,所以无论是直接写
如
map<string, string> str_map;
str_map["alex"] = "yes?";
str_map["Alex"] = "no!";
之后,这个map里的顺序就是
Alex-no!
alex-yes?
当然,这是我之后才顿悟到的. :)
具体问题是这样,我简化一下,由于需要在buf里写入值,再存到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() ) //若ID_不存在,则添加进去
str_map[ID_] = boost::lexical_cast<string> (buf);
之后,这个map会被写到html文件里。
结果当Instance > 9时,问题出现了。
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
如果有更好的解决方式请留言,共同交流呀
我的解决方式:关于map中含数字string的排序方式