概述
按照C Primer Plus中文第五版中的描述,long double 在使用scanf()函数读取时,应采用“%Lf" "%Le" "%Lg"作为控制字符串.
如下代码分别在VC 2010 Express 、MinGW(gcc version 4.8.1 (tdm-2))和QT5.2.1 for Desktop MinGW4.8 32bit 三种环境下测试。
#include <stdio.h> int main(void) { long double x_longdouble; scanf("%Lf", &x_longdouble); printf("%Le", x_longdouble); getchar(); getchar(); return 0; }
VC :能够编译并输入输出。
MinGW 和 QT:编译警报:
unknown conversion type character 'L' in format [-Wformat=] scanf("%Lf", &x_longdouble);
unknown conversion type character 'L' in format [-Wformat=] printf("%Le", x_longdouble);
输入: 0.234
VC:
0.234
2.340000e-001
MinGW:
0.234
0.000000e+000
QT:
0.234
2.340000e-001
google之后,找到一篇文章。
http://bytes.com/topic/c/answers/135253-printing-long-double-type-via-printf-mingw-g-3-2-3-a
“MINGW is broken regarding long double. I had reported this myself some time ago, and in summary here is what is going on: In Windows world double and long double is the same. However in MINGW long double is larger than double, however (I do not know more specifics) it can print only the long double of MS Windows, that is the double. They are using an MS library or something. You have two options. Either stick to double which is the same in Windows world, or use DJGPP which is another GCC port (but creates 32-bit DOS executables).
Or use some other compiler.”
附:
查看MinGW中gcc版本的方法:通过power shell进入gcc所在目录(...MinGWbin)执行命令:.gcc -v
转载于:https://www.cnblogs.com/stayathust/p/3800617.html
最后
以上就是糟糕羊为你收集整理的关于"long double"的困惑的全部内容,希望文章能够帮你解决关于"long double"的困惑所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复