【发布时间】:2021-09-16 06:15:10
【问题描述】:
[在此处输入图像描述][1]我正在做一个非常简单的程序,将一些值转换为任何特定的数据类型,其中浮点数转换为 3 精度值和双精度值。这是我的代码:-
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a;
long b;
char c;
float d;
double e;
cin >> a >> b >> c >> d >> e;
cout << "\nUsing cin & cout\n" << endl;
cout << a << endl << b << endl << c << endl;
cout << fixed << setprecision(3) << d << endl;
cout << fixed << setprecision(9) << e << endl;
cout << "\nUsing scanf and printf\n" << endl;
printf("%d\n", a);
printf("%ld\n", b);
printf("%c\n", c);
printf("%.3f\n", d);
printf("%.9lf\n", e);
return 0;
}
测试用例:-
输入:- 3 12345678912345 a 334.23 14049.30493
正确的输出:-
3
12345678912345
a
334.230
14049.304930000
此代码通过了所有测试用例,但在 windows 中输出错误,我在 vscode、cmd、powershell 中尝试过。并且在在线编译器和 linux 系统中运行良好。
Windows 输出:- https://i.imgur.com/GrQJTyb.png
Linux 输出:- https://i.imgur.com/a5t4Hxu.png
如何在我的系统中解决这个问题,请帮忙。
【问题讨论】:
-
请直接在此处发布输出,请勿使用外部链接。
-
12345678912345-- 这适合long吗?std::numeric_limits<long>::max()是什么?此外,您没有提及您正在使用的实际 Windows 编译器。 VSCode 和 Powershell 不是 C++ 编译器。使用uint64_t,而不是long。