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;
}
}
你可能會考慮再添加一行來調用你的向量的std :: sort()。 –