我想从文本文件中读取 double 例如 31 39.9316476397222 116.113516352222
我都试过了,都不行。我只能读取前几个十进制数字,例如39.93164 但不是 39.9316476397222 有谁知道为什么?谢谢!
int NodeID;
double _lat,_long;
fscanf (pFile, "%d %lf %lf", &NodeID,&_lat,&_long);
printf ("I have read: %d %f %f\n", NodeID,_lat,_long);
fscanf (pFile, "%d %lf %lf", &NodeID,&_lat,&_long);
printf ("I have read: %d %lf %lf\n", NodeID,_lat,_long);
最佳答案
根据fscanf man page , 你应该使用 %lf
来加倍 :
f, e, g (Floating point number) : A series of decimal digits, optionally containing a decimal point, optionally preceeded by a sign (+ or -) and optionally followed by the e or E character and a decimal integer (or some of the other sequences supported by strtod). Implementations complying with C99 also support hexadecimal floating-point format when preceded by 0x or 0X.
关于c++ - 使用 fscanf 读取双倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17852269/