u010540481 2014-04-07 09:37 采纳率: 0%
浏览 1219

一用到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时,程序就出现“栈溢出”。

  • 写回答

1条回答

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-20 17:59
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘