本文介绍了错误:“operator&'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下错误
我的代码如下:
#include< iostream>
#include< cstdlib>
#include< ctime>
using namespace std;
int main()
{
string board [3] [3];
board [0] [0] =[];
board [0] [1] =[];
board [0] [2] =[];
board [1] [0] =[];
board [1] [1] =[];
board [1] [2] =[];
board [2] [0] =[];
board [2] [1] =[];
board [2] [2] =[];
string choice;
int counter;
do
{
for(counter = 0; counter< 5; counter ++)
{
cout<< board [0] [0]< board [0] [1]<< board [0] [2]<< endl;
cout<< board [1] [0]<< board [1] [1]
cout<< board [2] [0]<< board [2] [1]
cout<<(Player 1)告诉我你想要你的X坐标的坐标:;
cin>>选择;
cout<< endl;
if(choice ==1,1)
{
board [0] [0] =[X];
}
else if(choice ==1,2)
{
board [1] [0] =[X]
}
else if(choice ==1,3)
{
board [2] [0] =[X];
}
else if(choice ==2,1)
{
board [0] [1] =[X];
}
else if(choice ==2,2)
{
board [1] [1] =[X];
}
else if(choice ==2,3)
{
board [2] [1] =[X];
}
else if(choice ==3,1)
{
board [0] [2] =[X];
}
else if(choice ==3,2)
{
board [1] [2] =[X];
}
else if(choice ==3,3)
{
board [2] [2] =[X];
}
if(board [0] [0]&&&& board [0] [1]&& || board [1] [0]&&&& board [1] [1]&& & board [2] [1]&&& board [2] [2] ==[X]|| board [0] [0]&& ; board [2] [0] ==[X]|| board [0] [1]&& X]|| board [0] [2]&&&& && board [1] [1]&& board [2] [2] ==[X]|| board [2] [0]& ;& board [0] [2] ==[X]||)
{
cout<<Player 1 wins!<< endl;
}
}
}
while(counter return 0;
}
错误on是以下内容:
if(board [0] [0]&& board [0] [1]& ;& board [0] [2] ==[X]|| board [1] [0]&& amp; board [1] [1]&& [X]|| board [0] [|| board] [2] [0]&& 0]&&&&&& board [2] [0] ==[X]|| board [0] [1] ]&& board [2] [1] ==[X]|| board [0] [2]&& ==[X]|| board [0] [0]&&&&& ] [0]&&&&&&&&&#1 [ p $ p>
解决方案您需要更改以下内容:
board [0] [0]&& board [0] [1]&& board [0] [2] ==[X]
To:
board [0] [0] ==[X]&& board [0] [1] ==[X]&& board [0] [2] ==[X]
是布尔值
I'm getting the following error
My code is the following:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
string board[3][3];
board[0][0] = "[ ]";
board[0][1] = "[ ]";
board[0][2] = "[ ]";
board[1][0] = "[ ]";
board[1][1] = "[ ]";
board[1][2] = "[ ]";
board[2][0] = "[ ]";
board[2][1] = "[ ]";
board[2][2] = "[ ]";
string choice;
int counter;
do
{
for(counter=0;counter<5;counter++)
{
cout<<board[0][0]<<board[0][1]<<board[0][2]<<endl;
cout<<board[1][0]<<board[1][1]<<board[1][2]<<endl;
cout<<board[2][0]<<board[2][1]<<board[2][2]<<endl;
cout<<"(Player 1) Tell me the coordinates of where you want your X togo: ";
cin>>choice;
cout<<endl;
if(choice=="1,1")
{
board[0][0] = "[X]";
}
else if(choice=="1,2")
{
board[1][0] = "[X]";
}
else if(choice=="1,3")
{
board[2][0] = "[X]";
}
else if(choice=="2,1")
{
board[0][1] = "[X]";
}
else if(choice=="2,2")
{
board[1][1] = "[X]";
}
else if(choice=="2,3")
{
board[2][1] = "[X]";
}
else if(choice=="3,1")
{
board[0][2] = "[X]";
}
else if(choice=="3,2")
{
board[1][2] = "[X]";
}
else if(choice=="3,3")
{
board[2][2] = "[X]";
}
if(board[0][0] && board[0][1] && board[0][2] == "[X]" || board[1][0] && board[1][1] && board[1][2] == "[X]" || board[2][0] && board[2][1] && board[2][2] == "[X]" || board[0][0] && board[1][0] && board[2][0] == "[X]" || board[0][1] && board[1][1] && board[2][1] == "[X]" || board[0][2] && board[1][2] && board[2][2] == "[X]" || board[0][0] && board[1][1] && board[2][2] == "[X]" ||board[2][0] && board[1][1] && board[0][2] == "[X]" ||)
{
cout<<"Player 1 wins!"<<endl;
}
}
}
while(counter<5);
return 0;
}
The line the error is on is the following:
if(board[0][0] && board[0][1] && board[0][2] == "[X]" || board[1][0] && board[1][1] && board[1][2] == "[X]" || board[2][0] && board[2][1] && board[2][2] == "[X]" || board[0][0] && board[1][0] && board[2][0] == "[X]" || board[0][1] && board[1][1] && board[2][1] == "[X]" || board[0][2] && board[1][2] && board[2][2] == "[X]" || board[0][0] && board[1][1] && board[2][2] == "[X]" ||board[2][0] && board[1][1] && board[0][2] == "[X]" ||)
解决方案 You need to change something like:
board[0][0] && board[0][1] && board[0][2] == "[X]"
To:
board[0][0] == "[X]" && board[0][1] == "[X]" && board[0][2] == "[X]"
So that the inputs on each side of the && are boolean values
这篇关于错误:“operator&'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!