我知道问这样一个问题似乎有点奇怪,但我很烦!
char winnerCheck[5];
if (winnerCheck=={'X','X','X','X','X'})
{
cout<<second<<", you won the game!";
}
它给了我(
[Error] expected primary-expression before '{' token
)作为第二行。提前致谢
最佳答案
远离传统的C阵列。使用std::array
很简单:
std::array<char, 5> winnerCheck;;
if (winnerCheck == std::array{'X','X','X','X','X'})
{
}
如果您还没有C++ 17,则只需添加
std::array
模板参数:std::array<char, 5> winnerCheck;;
if (winnerCheck == std::array<char, 5>{'X','X','X','X','X'})
{
}
关于c++ - 如何检查数组是否等于一组值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53708332/