第29397题 单选题
以下C++代码片段中,可正确实现以总宽度为8、保留2位小数的格式输出浮点数12.345的是?

使用C++标准库的格式化输出功能时,需注意相关头文件的包含,以及不同格式化修饰符的作用差异。

A

#include <iostream> using namespace std; int main() { cout << setw(8) << fixed << setprecision(2) << 12.345 << endl; return 0; }

B

#include <iostream> #include <iomanip> using namespace std; int main() { cout << setw(8) << fixed << setprecision(2) << 12.345 << endl; return 0; }

C

#include <iostream> #include <iomanip> using namespace std; int main() { cout << setw(8) << setprecision(2) << 12.345 << endl; return 0; }

D

#include <iostream> #include <iomanip> using namespace std; int main() { cout << fixed << setprecision(2) << 12.345 << endl; return 0; }

程序运行统计
暂无判题统计
提交0次 正确率0.00%
答案解析