2017-10-04 38 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)。

相关问题