一个关于map排序错误的问题
以下是一个完整的测试程序
#include<sstream>
#include<fstream> // 标准库文件IO部分的头文件
#include <iostream>
#include <string>
#include <boost/algorithm/string/find.hpp>
#include <map>
#include <vector>
using namespace std;
template <class T> string BeString(T originalPara)
{
stringstream oss;
oss<<originalPara;
string generateString(oss.str());
oss.str();
return generateString;
}
map<int, string> mapRank;
struct exampleClass
{
exampleClass(string name,int value)
{
this->name=name;
this->value=value;
}
string name;
int value;
};
vector<exampleClass> exampleVector;
int main(int argc, char *argv[])
{
for(int a=10;a>0;a--)
{
exampleVector.push_back(exampleClass(BeString(a),a));
}
map<string,float> m ;
//插入元素,按键值的由小到大放入黑白树中
for(int a=0;a<10;a++)
{
m[exampleVector[a].name]=exampleVector[a].value;
}
//先前遍历元素
map<string,float> :: iterator it ;
for(it = m.begin() ; it != m.end() ; it ++)
{
cout << (*it).first << " : " << (*it).second << endl ;
}
return 0;
}
在ubuntu下编译后运行的结果是
root@iZwz93vworsqnb3sjvkx5uZ:~# ./test.out
1 : 1
10 : 10
2 : 2
3 : 3
4 : 4
5 : 5
6 : 6
7 : 7
8 : 8
9 : 9
非常疑惑的是为什么10跑到上面去了