C++ if statements using strings not working as intended

前端 未结 4 998
名媛妹妹
名媛妹妹 2020-12-06 21:38

I have searched for this error but noone seems to be having the same problem as me. I am trying to make a basic text based RPG game in C++ to learn, and I want the user to b

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 22:34

    If you're using a C string (char[]), you need to use strcmp() to compare it. If the two strings are equivalent, it will return 0.

    if (strcmp(current_move, "ATTACK") == 0) will return true if they match.

提交回复
热议问题