我得到的错误来自{在底部,但是我在其他地方做错了导致错误?我该如何解决这个问题?
#include <iostream>
#include <string>
#include<stdafx.h>
using namespace std;
char Board[9];
//Declare Functions
int main()
{
char Board[9];
//Values for playing board
Board[0] = '0';
Board[1] = '1';
Board[2] = '2';
Board[3] = '3';
Board[4] = '4';
Board[5] = '5';
Board[6] = '6';
Board[7] = '7';
Board[8] = '8';
}
int showBoard();
{ //THIS IS WHERE THE ERROR IS COMING FROM
cout << endl;
cout << Board[0] << "|" << Board[1] << "|" << Board[2] << endl;
cout << "-+-+-" << endl;
cout << Board[3] << "|" << Board[4] << "|" << Board[5] << endl;
cout << "-+-+-" << endl;
cout << Board[6] << "|" << Board[7] << "|" << Board[8] << endl;
cout << endl;
}
答案 0 :(得分:1)
函数定义不能包含分号。从int showBoard()
的末尾删除分号。
您需要在使用函数之前声明函数,其中定义计为声明。所以写
int showBoard();
在打电话之前。
showBoard
将从全局范围打印(未初始化的)数组board
的(未定义)值。要在Board
中使用数组main
,请将其作为char*
传递给showBoard
。