在尝试从向量中删除字符串时,我看到了一些严重的错误消息。我正在尝试使用擦除删除成语,但它不起作用。这里有一些片段来说明我的困境。
team.players.erase( remove(team.players.begin(), team.players.end(),
player_name), team.players.end());
team.players 在这个结构中声明:
struct team
{
string name;
player captain;
vector<player> players;
};
向量 team.players 在程序运行时动态填充,并且在某些时候,用户可以选择通过菜单删除玩家。
if (select_option == PRINT_TEAM) print_team(team);
if (select_option == CHANGE_TEAM_NAME) change_team_name(team);
if (select_option == CHANGE_CAPTAIN) change_captain(team);
if (select_option == ADD_PLAYER) add_player(team);
if (select_option == REMOVE_PLAYER) remove_player(team);
if (select_option == QUIT) exit(0);
但是,当我试图编译我的程序(clang++)时,我得到了这些错误,早在调用函数之前。以下是错误:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:865:22: error: invalid operands to binary expression ('player' and 'const std::__1::basic_string<char>')
if (*__first == __value_)
~~~~~~~~ ^ ~~~~~~~~
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:2125:22: note:
in instantiation of function template specialization
'std::__1::find<std::__1::__wrap_iter<player *>, std::__1::basic_string<char> >'
requested here
__first = _VSTD::find(__first, __last, __value_);
^
program2.cpp:172:25: note: in instantiation of function template specialization
'std::__1::remove<std::__1::__wrap_iter<player *>, std::__1::basic_string<char>
>' requested here
team.players.erase( remove(team.players.begin(), team.players.end(),
^
2 errors generated.
知道如何解决这个问题吗?