C++里面怎样控制输出格式?

来源:百度知道 编辑:UC知道 时间:2024/05/31 14:04:02
比如让5输出为5.00

#include "iostream.h"
#include "iomanip.h"
void main()
{
int a = 5;

cout << setiosflags(ios::fixed)<<setprecision(2)<<(float)a<<endl;

}

假设a等于5 cout<<%.2f<<a<<endl cout<<%d<<a<<endl cout<<%m.nf<<a<<endl m表示整数,n表示小数位数 你自己上网搜一下吧,几句话说不清楚的