我是新來的stl's。這是我的下面的程序。如何讓stl :: map不區分大小寫
typedef pair<string, int> p;
int main(int argc, char *argv[])
{
map<string,int> st;
st.insert(p("hello",1)); //Inserted "hello" as key to map.
st.insert(p("HELLO",1)); //Inserted "HELLO" as key to map.
cout<<"size="<<st.size()<<endl; //Output is 2 because two records found "hello" and "HELLO"
return 0;
}
我不想考慮的情況下,反覆變化(大寫爲小寫字或反之亦然)。這裏「st.insert(p(」HELLO「,1));」應該失敗,因此沒有。的記錄應該是「1」而不是「2」。是否有任何標誌設置或類似?
我無法找到相關的問題,因此發佈了這個問題。
任何幫助是感謝。
最簡單的方法是在添加到地圖之前將它們變成小寫。 – zch