我想要一種方法,它需要一個字符串,並給出每個字符的字符頻率並將其存儲在二維數組或2D矢量中。當我運行代碼時,我不斷收到編譯器錯誤,但我不確定它說的是什麼。我已經對錯誤進行了一些研究,但仍然無法解決問題。我認爲必須有某種頭文件丟失或者是因爲被引用的類不是我的。在向量上使用find()時發生編譯器錯誤C++
vector<pair<char, int>> CaesarCypher::charFreqGen(string inputFileName)
{
string input = GetInputString(inputFileName);
vector<pair<char, int>> output;
for (auto c : input)
{
auto it = find(output.begin(), output.end(),[=](const pair<int, char>& p) {return p.first == c; });
if (it != output.end())
it->second++;
else
output.push_back(std::make_pair(c, 1));
}
return output;
}
這裏是我recieving錯誤:
Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::pair<char,int>' (or there is no acceptable conversion) c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 3026 1 PA1_CaesarCypher
謝謝!它現在工作 – user977154