c c++ 数据类型-一用到double型就出现“栈溢出”

问题描述

一用到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-08-30 04:19:15

c c++ 数据类型-一用到double型就出现“栈溢出”的相关文章

double类型-在MFCGridCtrl要显示DOUBLE型的数据

问题描述 在MFCGridCtrl要显示DOUBLE型的数据 我在其他窗口获取了数据,在MFCGridCtrl要显示这些数据!但是在其中有2项数据没有正常的显示出来. Item.szText.Format("%s",pDoc->m_SDate[m_text][row-1]+pDoc1->m_SDate[m_text+1][row-a]);这行是显示文字,可以正常显示出来 Item.szText.Format("%.3f",pDoc->m_edt_t

参数-请问double型能直接在QVECtor里赋值么?

问题描述 请问double型能直接在QVECtor里赋值么? QVector val(100000); int n; double y; while(n<100000) { y=val[n]; n++ } double型的参数能直接从Qvector里被赋值么?上面的赋值对不对? 解决方案 val[n]; 的数据类型要显示或隐式转换为double就可以

code::blocks中把10^9定义成double型没有溢出定义成long double型却溢出

问题描述 code::blocks中把10^9定义成double型没有溢出定义成long double型却溢出 code::blocks(GNU GCC Complier)中把10^9定义成double型没有溢出,定义成long double型反倒溢出了.而10^9既没有超过double的范围,更没有超过Long double的范围,这是GNU GCC Complier的bug吗?我的code::blocks是16.01的,已经是最新版了. #include #include double a;

java-我懂!是进制的问题导致Java的double型运算结果显示有精度问题,但是!!

问题描述 我懂!是进制的问题导致Java的double型运算结果显示有精度问题,但是!! 20C 但是,做笔试的时候,遇到这样一道题:下列表达式中,可以得到精确结果的是哪些?A.double d1 = 3.0-2.6:B.double d2 = 2.5*1.5:C.double d3 = 3.0-2.5:D.double d4 = 1.0-0.6:E.double d5 = 4.015*100:F.double d6 = 4.015*10: 实在是遇到这样的挫科的题目,我临场时该怎么解噜?!总不

在c#中将double型使用convert.ToInt转换为int型的小数点取舍问题,求大神解答

问题描述 在c#中将double型使用convert.ToInt转换为int型的小数点取舍问题,求大神解答 解决方案 解决方案二:double转成int,无非就是小数点第一位的取舍问题了,如果要四舍五入,那么+0.5之后再转解决方案三:四舍五入有专门的函数,你可以直接调用,如果强制转换话,只是取得整数部分

解一元二次方程 数据类型用float与double结果不同

问题描述 解一元二次方程 数据类型用float与double结果不同 #include #include main() { float a,b,c,d,r,x,x1,x2; scanf("%f %f %f",&a,&b,&c); r=b*b-4*a*c; d=2*a; if(a==0||b==0) printf("Input error!n"); if(r>0) printf("x1=%fnx2=%fn",(-b+s

double精度问题-两个double型变量相乘 在VC中结果不正确

问题描述 两个double型变量相乘 在VC中结果不正确 各位大侠,在VC2010中遇到以下问题,如能解决,必重谢. 两个double型变量相乘,如3.0*0.00095673,应该为0.00287019,但是在VC中这个值是0.002870189999999999,这样的话我们后面有一步需要进行(int)(3.0*0.00095673/0.00095673),真实结果应该为3,但是在VC中这个值却是2,这在我们程序中就会带来一定的计算误差. 现在想知道这样的计算误差能不能通过什么方式处理掉呢?

gson默认将int型转换成double型怎么解决?

问题描述 gson默认将int型转换成double型怎么解决? android中gson解析的数据库id如:1:2:3:会变成1.0:2.0:3.0:每个int型都会变成double型,这个应该怎么解决? 解决方案 不是使用getInt()吗,怎么会解析成double? 解决方案二: 是你的字段定义的是double型吧,否则不会乱转换的,看你代码中或数据库中是否为double

c#中double型的输出代码怎么写通用性更强?

问题描述 c#中double型的输出代码怎么写通用性更强? c#中double型的输出代码怎么写通用性更强?就是可以在控制台输出同样的代码也可以在其他窗体输出么? 解决方案 将输出代码包装成委托: 假设这是你之前的代码 void foo() { double d = 123.456; Console.WriteLine(d); } 为了通用,你需要把输出的部分抽取出来,变成 void foo(Action<double> output) { double d = 123.456; output