[問題] 程式記憶體區段錯誤?
小弟是用Linux寫程式
編譯器是g++
我只是寫了一個讀檔的程式要存data至陣列
編譯也都沒問題
可是執行 ./a.out 以後卻會出現
"程式記憶體區段錯誤"
請問這是什麼意思
不好意思 我不確定這是程式的問題還是Linux的問題
code
----
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
ifstream inFile( "data.dat", ios::in );
if ( !inFile ){
cerr<<"File could not be opened"<<endl;
exit( 1 );
}
ofstream outFile( "3Ddata.dat", ios::out );
if ( !outFile ){
cerr<<"File could not be opened"<<endl;
exit( 1 );
}
double x;
double y;
double z;
double vx;
double vy;
double vz;
int counter = 0;
double xyz[180][180][180]={0};
while ( inFile >> x >> y >> z >> vx >> vy >> vz ){
counter = counter+1;
int xgrid = 90+x/0.04;
int ygrid = 90+y/0.04;
int zgrid = 90+z/0.04;
if(xgrid>=0 && ygrid>=0 && zgrid>=0 && xgrid<180 && ygrid<180 &&
zgrid<180){
xyz[xgrid][ygrid][zgrid] = xyz[xgrid][ygrid][zgrid]+1.0;
}
cout<< counter <<endl;
}
int i,j,k;
for(i=0; i<180; i++){
for(j=0; j<180; j++){
for(k=0; k<180; k++){
xyz[i][j][k]= xyz[i][j][k]*(1.29e+8)/(0.04*0.04*0.04);
outFile<<(i-90)*0.04+0.02<<" "<<(j-90)*0.04+0.02<<" "<<(k-90)*0.04+
0.02<< " "<<xyz[i][j][k]<<endl;
}
}
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.235
推
08/31 19:49, , 1F
08/31 19:49, 1F
→
08/31 19:50, , 2F
08/31 19:50, 2F
→
08/31 19:50, , 3F
08/31 19:50, 3F
貼了
※ 編輯: peter74123 來自: 140.112.4.235 (08/31 20:16)
推
08/31 20:38, , 4F
08/31 20:38, 4F
→
08/31 20:39, , 5F
08/31 20:39, 5F
→
08/31 20:39, , 6F
08/31 20:39, 6F
推
08/31 22:48, , 7F
08/31 22:48, 7F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章