C++入门经典-例2.11-流输出小数控制

1:代码如下:

// 2.11.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
    float x=20,y=-400.00;
    cout << x <<' '<< y << endl;//输出x,空格,y
    cout.setf(ios::showpoint);    //强制显示小数点和无效0
    cout << x <<' '<< y << endl;
    cout.unsetf(ios::showpoint);
    cout.setf(ios::scientific);    //设置按科学表示法输出
    cout << x <<' '<< y << endl;
    cout.setf(ios::fixed);        //设置按定点表示法输出
    cout << x <<' '<< y << endl;
}
View Code

运行结果:

posted @ 2017-09-11 16:27  一串字符串  阅读(205)  评论(0编辑  收藏  举报