Program expects a bracket, but there is one there already there

自古美人都是妖i 提交于 2020-01-16 13:46:07

问题


#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;

#define ARRAYSIZE  15;


int main(void)
{
    //things needed
    ifstream infile;
    ofstream outfile;

    double xArray[ARRAYSIZE];


}

As you can see, my code should be in order but my program keeps telling me it expects a '[' where the xArray[ARRAYSIZE] is. By the way I'm using microsoft visual studio 2013.


回答1:


#define ARRAYSIZE 15

Take the ; out of the #define.

With your #define written as is,

double xArray[ARRAYSIZE];

translates to

double xArray[15;];

The compiler expects a ] before the first ;.


Doing this:

const int ARRAYSIZE 15;

might be better...




回答2:


after preprocess, your code is kind of

int main(void)
{
    //things needed
    ifstream infile;
    ofstream outfile;

    double xArray[15;];  // replace ARRAYSIZE with 15;
}

so you have to remove ; in #define

#define ARRAYSIZE  15



回答3:


#define ARRAYSIZE 15;

Define will substitute ARRAYSIZE with whatever is there next to it.

So in this case it will substitute ARRAYSIZE with 15;

So all you need to do is just remove the semi-colon in the define statement



来源:https://stackoverflow.com/questions/20389679/program-expects-a-bracket-but-there-is-one-there-already-there

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!