<分区>
我是 C++ 的新手,因为我的第一个任务是制作黑白棋游戏,但在更换棋子时遇到了问题。我试图比较字符串元素,但没有任何反应。这是向您展示问题所在的代码。
#include <iostream>
#include <string>
using namespace std;
void displayTop();
int main() {
string board [8][8] = {
" "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," ",
" "," "," ","W","B"," "," "," ",
" "," "," ","B","W"," "," "," ",
" "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," ",
" "," "," "," "," "," "," "," ",
};
displayTop();
cout << endl;
for (int row = 0; row < 8; row++){
cout << " ";
for (int column = 0; column < 8; column++){
cout << board[row][column] << " ";
}
cout << endl;
displayTop();
cout << endl << endl;
}
if(board[0][0] == " "){
board[0][1] = "W";
}
}
void displayTop(){
for (int i = 0; i < 8; i++){
cout << "+----";
}
cout << endl;
}