String is not allowed in Switch statements It is recommended that you create a separate ID that points to the specified string and compare it.
#include <iostream>
#include <map>
#define BUFFER 256
int main()
{
enum EnumTeam
{
eTeamKt = 1, eTeamFin
};
std::map<std::string, EnumTeam> teamList;
char str[BUFFER] = "";
int select = 0;
teamList["Kt"] = eTeamKt;
teamList["Fin"] = eTeamFin;
std::cout << "Team Select >> ";
std::cin >> str; // Input
switch (teamList[str])
{
case eTeamKt:
select = (int)eTeamKt; break;
case eTeamFin:
select = (int)eTeamFin; break;
}
std::cout << "Team : " << select << std::endl;
system("pause");
return 1;
}
The switch statement cannot contain a string.
Only availablenumber or letters and
.Characters are also actually applied internally to the ascii numeric value.
To use a string, use the if statement to use the entered string
Convert to a separate integer value and use it for the switch door.
© 2024 OneMinuteCode. All rights reserved.