问题描述
- 一用到double型就出现“栈溢出”
-
代码
#include "stdafx.h"
#include "stdio.h"
#include "math.h"
#include "iostream"
using namespace std;typedef struct Mystruct1
{
double X;
double Y;
double Z;
bool Type;
}Point;int _tmain(int argc, _TCHAR* argv[])
{
//Open the LiDAR File
FILE *fp=fopen("F:LiDAR.txt","r");
if (!fp)
{
cout<<"Failed to open the file,LiDAR.txt";
}//Read the LiDAR Data Point p[50000]; fseek(fp,0,2); int i=ftell(fp);//To get the length of the file. fseek(fp,0,0); int k=0; for (int j=ftell(fp);j<=i;k++) { fread(&p[k].X,8,1,fp); fread(&p[k].Y,9,1,fp); fread(&p[k].Z,5,1,fp); fread(&p[k].Type,1,1,fp); } //Tell us the number of points. for (i=0;i<=50000;i++) { if (!p[i].X && !p[i].Y && !p[i].Z && !p[i].Type) { printf_s("The number of the points is:n","%d",i); } } //Create the grids int minX=p[0].X,maxX=p[0].X,minY=p[0].Y,maxY=p[0].Y; for (int j=0;j<=i;j++) { if (minX>=p[j].X)minX=p[j].X; if (maxX<=p[j].X)maxX=p[j].X; if (minY>=p[j].Y)minY=p[j].Y; if (maxY<=p[j].Y)maxY=p[j].Y; } printf_s("The Area is:%f x %f",maxY-minY,maxX-minX); return 0;
}
问题描述
在结构体Point中,如果把成员X,Y,Z设成int型就不会出现“栈溢出”的错误;但是我的数据中基本上都是:
513547.92 5403429.81 288.45 0
513547.96 5403431.26 288.65 0
513548.06 5403433.00 292.42 1
513548.05 5403434.37 288.94 0
513548.13 5403436.04 291.73 1
513548.18 5403437.61 292.36 1
513548.18 5403439.00 288.95 0
513548.22 5403440.45 288.98 0
513548.26 5403468.67 287.86 0
513548.20 5403467.23 287.82 0
513548.14 5403465.68 287.78 0
这样的数字。而当我使用double型的X,Y,Z时,程序就出现“栈溢出”。
时间: 2024-10-31 22:53:59