我一直在試圖讓這個工作正常;但是,似乎我無法弄清楚這一點。我試圖讓遊戲板正確初始化,但它一直在說<error reading characters of string>
。c + +多維數組不會初始化
using namespace std;
int main()
{
board show;
show.init();
show.printing();
}
class board {
public:
void init(){
string Board[8][9] = {
{ "C56", "C15", "C21", "C62", "C11", "C62", "C21", "C15", "C56" },
{ " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 " },
{ " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 " },
{ " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 " },
{ " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 " },
{ " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 " },
{ " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 ", " 0 " },
{ "C56", "C15", "C21", "C62", "C11", "C62", "C21", "C15", "C56" },
};
}
void printing(){
string character = "*";
int position[2] = { 2, 2 };
// Draw the grid once
for (int i = 0; i < 8; i++){
for (int j = 0; j < 9; j++){
if (i == position[0] && j == position[1])
cout << character;
else
cout << Board[8][9];
cout << " ";
}
cout << endl;
}
}
private:
string Board[8][9];
};
'COUT <<局[8] [9];'使用兩個無效索引。您可能錯誤地輸入了「cout」Board [i] [j];'。 – molbdnilo