1
我正在閱讀斯坦福大學的教程,目前正在STL上解決任務。其任務是編寫一個函數,該函數接受帶有電影名稱和排名的map
。根據評論家的評論,這個功能應該會返回set
容器與前3部電影。這裏是我的解決方案:錯誤c2675使用STL VS13 C++
#include <iostream>
#include <set>
#include <map>
#include <numeric>
#include <iterator>
#include <string>
using namespace std;
struct compare {
bool operator() (const double& a, const double& b) const {
return (a > b);
}
};
set <string> list(map <double, string, compare>& films) {
set <string> critics;
map<double, string, compare> ::iterator it = films.begin();
if (films.size() <= 3) {
critics.insert(films.begin()->second, films.end()->second);
}
else {
for (int i = 0; i < 3; ++i, ++it){
critics.insert(it->second);
}
};
return critics;
}
int main() {
map <double, string, compare> films;
films[5.0] = "a";
films[8.0] = "b";
films[10.0] = "c";
films[7.4] = "d";
set <string> critics = list(films);
copy(critics.begin(), critics.end(), ostream_iterator <string>(cout, " "));
cin.get();
}
不幸的是,它不斷拋出的錯誤:
error C2675: unary '++' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
我看過MSDN文檔上的錯誤,但因爲我是新來這個無法理解的意思問題。請問,你能提醒我一下嗎?
喜維拉德。 – 2015-04-02 17:49:56
@Lightning Racis在OBRIT僑。來吧? – 2015-04-02 17:53:23
Bine,mulţumesc。 Şidumneavoastră? – 2015-04-02 17:57:40