2017-10-04 102 views
0

因此,我有一個程序讀取文件,並通過使用std::map並將int作爲關鍵字和std::vector作爲值來獲取最大單詞。我需要打印出最大的單詞,但在排序時遇到問題。而輸出應該是版權,出版,通用,藍圖 我得到:藍圖,版權,通用,出版使用大寫和小寫字母排序向量

我該如何解決這個問題?矢量不是大寫還是小寫? 這是我到目前爲止有:

string temp; 
stringstream ss(line); 
while(ss >> temp) { 
    int wordlength = temp.length(); 
    wordit = wordbycount.find(wordlength); 
    if (wordit != wordbycount.end()) { 
     vector<string> arrayofLongest = wordit->second; 
     std::vector<string>::iterator iterator1 = find(arrayofLongest.begin(), arrayofLongest.end(), temp); 
     if (iterator1 == arrayofLongest.end()) { 
      wordit->second.push_back(temp); 
     } 
    } 
    else { 
     wordbycount[wordlength] = temp; 
    } 
} 
+0

你可能會考慮再添加一行來調用你的向量的std :: sort()。 –

回答

0

待辦事項載體不是那種大寫和小寫?

std::vector s不排序(簡單地追加元素)。

std::vector s保持插入順序。

如果您需要插入和排序容器,則應使用std::set(或std::multiset)。

相關問題