错误 3 错误 C2447:'{':缺少函数标头(旧式正式列表?

Error 3 error C2447: '{' : missing function header (old-style formal list?)?

本文关键字:错误 列表 C2447 函数      更新时间:2023-10-16

我得到的错误是来自底部的{,但我做错了什么地方导致错误吗?我该如何解决这个问题?

#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;
}
  1. 函数定义不能包含分号。去掉int showBoard()末尾的分号

  2. 您需要在使用函数之前声明它们,其中定义算作声明。所以写

    int showBoard();
    
  3. showBoard将从全局作用域中打印(未初始化)数组board的(未定义)值。要在main中使用数组Board,将其作为char*传递给showBoard