【发布时间】:2017-10-16 19:35:45
【问题描述】:
我在 C++ 控制台应用程序中制作了一个简单的石头剪刀布游戏。到目前为止,游戏运行良好.. 直到我尝试将文件中的单词存储在变量中,然后尝试在 IF 语句中使用该变量。
这是我将文件中的单词存储在变量中的方式。
string comp_selection;
char player_selection;
这是我试图让它工作的代码部分。
cout << "Rock, Paper, or Scissors?";
cin >> player_selection;
if (comp_selection =='r' || comp_selection == 'R')
{
if (player_selection == 'r' || player_selection == 'R')
{
cout << "Computer chose " << comp_selection << "... It's a draw!" << std::endl;
}
else if (player_selection == 'p' || player_selection == 'P')
{
cout << "Computer chose " << comp_selection << "... You win!" << std::endl;
}
else if (player_selection == 's' || player_selection == 'S')
{
cout << "Computer chose " << comp_selection << "... You lose!" << std::endl;
}
}
输出应该是:
计算机选择了摇滚……你赢了!
例如,如果玩家选择了纸。 相反,我收到此错误消息
严重性代码描述项目文件行抑制状态 错误 C2678 二进制“==”:未找到采用“std::string”类型左侧操作数的运算符(或没有可接受的转换)
任何帮助或指导,都会很棒!提前谢谢了。
【问题讨论】:
-
查看错误!!未找到采用“std::string”类型的左侧操作数的运算符。您正在将 char 与 std::string 进行比较