c++ - 用scanf如何读入long double和unsigned char?
ringa_lee
ringa_lee 2017-04-17 11:10:18
[C++讨论组]

用scanf如何读入long double和unsigned char? 语言学得不精,还请众神指点…… 网上找了一下,可是照着打不行啊。。。 以下是代码和编译信息(c++)

#include <cstdio>
int main()
{
    unsigned char test;
    scanf("%hhu",&test);
    printf("%hhu",test);
    long double a;
    scanf("%Lf",&a);
    printf("%lf",a);
}

1625.cpp:9:20: warning: unknown conversion type character 'h' in format [-Wformat]

1625.cpp:9:20: warning: too many arguments for format [-Wformat-extra-args]

1625.cpp:10:20: warning: unknown conversion type character 'h' in format [-Wformat]

1625.cpp:10:20: warning: too many arguments for format [-Wformat-extra-args]

1625.cpp:12:16: warning: unknown conversion type character 'L' in format [-Wformat]

1625.cpp:12:16: warning: too many arguments for format [-Wformat-extra-args]

1625.cpp:13:16: warning: format '%lf' expects argument of type 'double', but argument 2 has type 'long double' [-Wformat]

ringa_lee
ringa_lee

ringa_lee

全部回复(1)
PHP中文网

国外已经有人提过类似的问题了。 点这里

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.

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号