数据文件test.txt中如下数据
3
10.026278 10.461819
.026278 10.461819
10.026278 40.461819
4
-24.718327 10.256420
-9.718327 10.256420
-24.718327 40.256420
-9.718327 40.256420
5
-25.701054 -40.155312
-10.701054 -40.155312
-25.701054 -10.155312
-10.701054 -10.155312
10.639103 -40.642311
void fun()
{
FILE *fp = fopen("test.txt","r");
double x,y;
int num;
//float x,y;
while (!feof(fp))
{
fscanf(fp, "%d\n", &num);
cout<<num<<endl;
for(int i=0; i<num; i++)
{
fscanf(fp, "%f%f", &x, &y);
cout<<x<<", "<<y<<endl;
}
cout<<endl;
}
}
如果采用x、y采用double类型,会输出如下指数形式(不是我想要的,结果也不对)
3
-9.25596e+061, -9.25596e+061
-9.25596e+061, -9.25596e+061
-9.25596e+061, -9.25596e+061
4
-9.25596e+061, -9.25596e+061
-9.25596e+061, -9.25596e+061
-9.25596e+061, -9.25596e+061
-9.25596e+061, -9.25596e+061
5
-9.25596e+061, -9.25596e+061
-9.25596e+061, -9.25596e+061
-9.25596e+061, -9.25596e+061
-9.25596e+061, -9.25596e+061
-9.25596e+061, -9.25596e+061
如果x、y采用float类型 读入的数据精度不够
3
10.0263, 10.4618
0.026278, 10.4618
10.0263, 40.4618
4
-24.7183, 10.2564
-9.71833, 10.2564
-24.7183, 40.2564
-9.71833, 40.2564
5
-25.7011, -40.1553
-10.7011, -40.1553
-25.7011, -10.1553
-10.7011, -10.1553
10.6391, -40.6423
请教大家怎么才能从文件中读入double 类型数据呢,并赋值给 double变量???