void'应该以';'开头 错误?

Nic*_*pto -1 visual-c++

所以我使用的是Visual Studio C++.我当前的程序是如此反向创建一个数组...但是我得到的错误是"void"应该以';'开头.帮助将不胜感激.

#include <iostream>

using namespace std;

int main()

//this function outputs the array in reverse
void reverse(double* a, int size)
{

for(int i = size-1; i >= 0; --i)//either i=size or i=size-1
{
cout << a[i] << ' ';
}
}
Run Code Online (Sandbox Code Playgroud)

jos*_*mas 6

你错过了一个开场{之后int main().

所以你的代码就是

int main()
{
//this function outputs the array in reverse
void reverse(double* a, int size)
Run Code Online (Sandbox Code Playgroud)

但是,还有其他错误.例如,您的主要不会返回值.而且你的程序结构应该不同.它应该是

#include <iostream>
using namespace std;

//this function outputs the array in reverse
void reverse(double* a, int size)
{
    for(int i = size-1; i >= 0; --i)//either i=size or i=size-1
    {
        cout << a[i] << ' ';
    }
}

int main()
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

通过格式化代码,很容易发现其中一些错误.由于您使用的是Visual Studio,因此执行此操作的默认设置为Ctrl + K和Ctrl + D.