運行下面的代碼時,我得到一個分段錯誤:未知分段故障
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然後賽格故障。任何想法,爲什麼會這樣?
方程文件的第102行有什麼?它是最後一行嗎? – olevegard
while循環可能會增加行數389 –
與其他行沒什麼區別。公式文件的格式如下所示:ECSBSensor56 0 0 0 0 0 0 0 0 ECSBSensor57 0 0 0 0 0 0 0 0 ECSBSensor58 0 0 0 0 0 0 0 0 ECSBSensor59 0 0 0 0 0 0 0 0 ECSBSensor60 0 0 0 0 0 0 0 0 ECSBSensor61 0 0 0 0 0 0 0 0 310行 – user2494298