0
点赞
收藏
分享

微信扫一扫

[C++] I/O格式控制

爱奔跑的读书者 2022-03-11 阅读 61
c++

I/O格式控制


  • C++中,可以使用操纵符(manipulator),来对输入输出进行控制
  • 要使用操纵符,需要在源程序的开头包含 iomanip 头文件
#include <iomanip>

一些常用的操纵符

操纵符功能
dec十进制格式输出
hex十六进制格式输出
oct八进制格式输出
fixed固定点格式输出
endl插入换行符
ends插入空格符
setprecision(int)设置数值精度

示例

int x = 1314;
float pai = 3.1415;

cout << hex << x << endl;
cout << pai << endl;
cout << setprecision(3) << pai;

/*
522

3.14159

3.14
*/

注: cout 默认输出数值精度为 6

举报

相关推荐

0 条评论