Is there a way to print the contents of this map in alphabetical order, but case insensitive?
Yes.
You will have to create a custom compare functor that compares two strings in a case insensitive manner.
struct cicompare { bool operator()(std::string const& lhsIn, std::string const& rhsIn) const { char const* lhs = lhsIn.c_str(); char const* rhs = rhsIn.c_str(); for ( ; *lhs != '\0' && *rhs != '\0'; ++lhs, ++rhs ) { if ( tolower(*lhs) != tolower(*rhs) ) { return ( tolower(*lhs) < tolower(*rhs) ); } else if ( *lhs != *rhs) { if ( *(lhs+1) == '\0' && *(rhs+1) == '\0' ) { return (*lhs < *rhs); } } } return (tolower(*lhs) < tolower(*rhs)); } };
Use the case insensitive compare functor to create the map.
map<string, map<int,int>, cicompare> mymap;
If you don't want to store your map ordered in a case insensitive manner, create a copy of the original map using
cicompare
just before printing and print the new map.map<string, map<int,int>, cicompare> mapForPrinting; mapForPrinting.insert(originalMap.start(), originalMap.end());