格式化输出相关

#include <iostream>
#include <iomanip>
using namespace std;

//格式化输出
int main()
{
	int x = -10;
	double d = 3.14;
	cout << x << d << endl;
	cout << '[' << setw(10) << x << ']' << endl;
	cout << left;
	cout << '[' << setw(10) << x << ']' << endl;
	cout << internal;
	cout << '[' << setw(10) << x << ']' << endl;

	//以指定进制输出
	x = 17;
	cout << oct << x << endl;
	cout << hex << x << endl;
	cout << dec << x << endl;
	cout << uppercase;
	cout << showbase << hex << x << endl;
	cout << showbase << oct << x << endl;
	cout << showbase << dec << x << endl;
	cout << showbase << x << endl;
	//以科学计数法打印
	cout << scientific << d << endl;
	cout << fixed << d << endl;
	//将缓冲区设置成一个字节
	cout << unitbuf;
	cout << "Hello";
	cerr << "World";
	cout << endl;
	cout << setfill('#'); 
	cout << setw(10) << x << endl;
	//设置浮点数的打印精度
	d = 3.1415;
	cout << setprecision(4);
	cout << d << endl;
}
/*  程序执行结果
-103.14
[       -10]
[-10       ]
[-       10]
21
11
17
0X11
021
17
17
3.140000E+00
3.140000
HelloWorld
########17
3.1415
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值