mySongs
是一个向量,存储用户输入的歌曲集合。在 if 语句中,程序将根据用户输入检查向量中的元素。如果匹配,它将从向量中删除该指定值。当我寻找解决方案时,我看到有人建议使用remove/erase idiom:。但是当我在我的代码中实现时,它会继续弹出这个错误C2678 binary '==': no operator found which takes a left - hand operand of type 'Song' (or there is no acceptable conversion)
void deleteSong() {
string songTitle;
cout << "\n\t\tPlease enter the particular song name to remove: ";
cin >> songTitle;
if (songTitle != "") {
for (Song songs : mySongs) {
if (songs.title == songTitle) {
mySongs.erase(find(mySongs.begin, mySongs.end, songs)); //erase an element with value
break;
}
}
}
}