按照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 三种环境下测试。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14#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:编译警报:
复制代码
1
2
3unknown conversion type character 'L' in format [-Wformat=] scanf("%Lf", &x_longdouble); unknown conversion type character 'L' in format [-Wformat=] printf("%Le", x_longdouble);
复制代码
1
输入: 0.234
VC:
复制代码
1
2
30.234 2.340000e-001
MinGW:
复制代码
1
2
30.234 0.000000e+000
QT:
复制代码
1
2
30.234 2.340000e-001
google之后,找到一篇文章。
http://bytes.com/topic/c/answers/135253-printing-long-double-type-via-printf-mingw-g-3-2-3-a
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
“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内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复