运行以下代码时出现分段错误:
const int SENSORS = 65;
static float coefficient[SENSORS][6];
const int NUMSUBSYSTEM = 6;
const int ALLSENSORS = SENSORS * NUMSUBSYSTEM;
using namespace std;
int row = 0;
static int outputError = -1; //static to retain value
ifstream equationFile("equation.txt");
static string sensorNameEquation[ALLSENSORS];
static float coefficientOverride[ALLSENSORS][6]; //static to keep large array off stack
static string dependantSensor[ALLSENSORS]; //static to keep large array off stack
static float baseTemp[ALLSENSORS]; //static to keep large array off stack
printf("Total sensors: %d\n", ALLSENSORS);
row = 0;
if(equationFile)
{
while( equationFile >>
sensorNameEquation[row] >>
coefficientOverride[row][0] >> coefficientOverride[row][1] >>
coefficientOverride[row][2] >> coefficientOverride[row][3] >>
coefficient[row][4] >> oefficient[row][5] >>
dependantSensor[row] >> baseTemp[row])
{
row++;
printf("sensors: %d\n", row);
}
equationFile.close();//done reading from file...close it
}
它到达方程文件的第 102 行,然后出现段错误。任何想法为什么会这样?