[問題]C++ reading double precision data
各位高手!!
請問一下!!我在從file讀double precision數值時
發現有個這樣的問題!!
//"test.txt"內容
//-5.000000 -7.56597e-200
//-4.999900 -7.5678e-006
//-4.999800 -7.56963e-006
//cout內容
//-5.000000 0.000000e+000
^^^^^^^^^^^^^^^^^^^^
//-4.999900 -7.5678e-006
//-4.999800 -7.56963e-006
我該如何解決呢???謝謝
//以下是程式碼!!
//////////////////////////////////////////////////
#include<iostream>
#include<math.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
main()
{
int i,col;
float value;
FILE *fp;
fp=fopen("test.txt","r");
col=2;
i=1;
while (fscanf(fp, "%f%*c", &value) != EOF)
{
printf("%e\t",value);
if(i%col==0)
{cout<<"\n";i=0;}
i++;
}
fclose(fp);
getch();
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.203.119.154
※ rabbit1983:轉錄至看板 C_and_CPP 03/24 04:05
討論串 (同標題文章)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章