问题
#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