#include
#include
using namespace std;
int main()
{
double a = 123.45665 , b = 3.1456 , c = -3214.67 ;
cout << setiosflags(ios::fixed) << setprecision(3) ;
cout << setw(10) << a << '\n'
<< setw(10) << b << '\n'
<< setw(10) << c << '\n' ;
return 0;
}
运行结果为
123.46
3.14
-3214.67
你是怎么运行程序的,通过IDE吗
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double a = 123.45665 , b = 3.1456 , c = -3214.67 ;
cout << setiosflags(ios::fixed) << setprecision(3) ;
cout << setw(10) << a << '\n'
<< setw(10) << b << '\n'
<< setw(10) << c << '\n' ;
return 0;
}
结果正常,如下:
123.457
3.146
-3214.670