Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <map>
- #include <string>
- using namespace std;
- int main(){
- // some data
- map<string, double> myList;
- myList["peter"]= 3.0;
- myList["paul"]= 1.0;
- myList["mary"] = 2.0;
- // sort the elements
- map<double, string> mySortedList;
- for ( map<string, double>::iterator i = myList.begin();
- i != myList.end();
- i++ )
- {
- mySortedList[ i->second ] = i->first;
- }
- // print the sorted elements
- cout << "sorted: ";
- for ( map<double, string>::iterator i = mySortedList.begin();
- i != mySortedList.end();
- i++ )
- {
- cout << i->first << " {" << i->second << "} ";
- }
- cout << "\n";
- }
And it works as I expect it with g++ 3.4.4 cygwin, but I'm anxious since
http://www.cppreference.com/cppmap/index.html
only says that maps are sorted, but not whether that is ascending or descending or whatever-map-blackmagic-sorting.
Anybody able to clarify this?