1
我有一個包含足球隊信息的班級團隊。我需要閱讀一個文件,並將每個獨特的團隊添加到矢量季節。查找向量中的特定元素
//循環來確定唯一的球隊
if(season.size() <= 1)
{
season.push_back(new_team);
cout << "First team added!" << endl;
}
vector<team>::iterator point;
point = find(season.begin(), season.end(), new_team);
bool unique_team = (point != season.end());
if(unique_team == true && season.size()>1)
{
season.push_back(new_team);
cout << "New team added!" << endl;
}
cout << "# of Teams: " << season.size() << endl;
system("pause");
任何想法,爲什麼這不起作用?我仍然對此感到陌生:-)因此,請隨時給予建設性的批評。
我覺得你的邏輯可能有點過,不應該一隊加入當賽季矢量的大小爲0。如果一線隊已經加入你並不需要檢查它是否在矢量中再次添加它。您的查找(...)代碼正常工作。 – jazzdawg