控制台IO操作函数
来源:互联网 发布:卖家淘宝账目在哪里 编辑:程序博客网 时间:2024/05/17 07:57
如果喜欢用控制台做输出,可以了解一下std提供的io控制函数。
setw
指定显示的宽度.
setprecision
设置输出floating-point精度
setfill
设置对其字符
setbase
设置整数进制
setprecision
设置指定的标志
resetiosflags
清除指定的标志
下面给出MSDN上的一个例子:
#include <iostream>#include <iomanip>using namespace std;const double d1 = 1.23456789;const double d2 = 12.3456789;const double d3 = 123.456789;const double d4 = 1234.56789;const double d5 = 12345.6789;const long l1 = 16;const long l2 = 256;const long l3 = 1024;const long l4 = 4096;const long l5 = 65536;int base = 10;void DisplayDefault( ){ cout << endl << "default display" << endl; cout << "d1 = " << d1 << endl; cout << "d2 = " << d2 << endl; cout << "d3 = " << d3 << endl; cout << "d4 = " << d4 << endl; cout << "d5 = " << d5 << endl;}void DisplayWidth( int n ){ cout << endl << "fixed width display set to " << n << ".\n"; cout << "d1 = " << setw(n) << d1 << endl; cout << "d2 = " << setw(n) << d2 << endl; cout << "d3 = " << setw(n) << d3 << endl; cout << "d4 = " << setw(n) << d4 << endl; cout << "d5 = " << setw(n) << d5 << endl;}void DisplayLongs( ){ cout << setbase(10); cout << endl << "setbase(" << base << ")" << endl; cout << setbase(base); cout << "l1 = " << l1 << endl; cout << "l2 = " << l2 << endl; cout << "l3 = " << l3 << endl; cout << "l4 = " << l4 << endl; cout << "l5 = " << l5 << endl;}int main( int argc, char* argv[] ){ DisplayDefault( ); cout << endl << "setprecision(" << 3 << ")" << setprecision(3); DisplayDefault( ); cout << endl << "setprecision(" << 12 << ")" << setprecision(12); DisplayDefault( ); cout << setiosflags(ios_base::scientific); cout << endl << "setiosflags(" << ios_base::scientific << ")"; DisplayDefault( ); cout << resetiosflags(ios_base::scientific); cout << endl << "resetiosflags(" << ios_base::scientific << ")"; DisplayDefault( ); cout << endl << "setfill('" << 'S' << "')" << setfill('S'); DisplayWidth(15); DisplayDefault( ); cout << endl << "setfill('" << ' ' << "')" << setfill(' '); DisplayWidth(15); DisplayDefault( ); cout << endl << "setprecision(" << 8 << ")" << setprecision(8); DisplayWidth(10); DisplayDefault( ); base = 16; DisplayLongs( ); base = 8; DisplayLongs( ); base = 10; DisplayLongs( ); return 0;}
- 控制台IO操作函数
- IO操作系列函数
- 控制台IO
- java IO总结之字节流操作控制台输入输出
- java IO总结之字符流操作控制台输入输出(高效)
- Java 控制台 IO
- 控制台函数
- 文件IO、目录操作和标准IO\涉及的函数
- c# 文件操作等IO函数
- c# 文件操作等IO函数
- 驱动程序操作IO口API函数
- 内核IO操作函数 __raw_readl和__raw_writel
- 派遣函数(3) - IO设备控制操作
- C文件IO操作函数笔记。
- Linux文件操作与IO函数
- java IO总结之字节流操作控制台输入输出(高效)
- IO中使用缓冲读写操作控制台数据的newLine()方法
- IO操作文件内容打印到控制台,将文件内容复制到另外一个文件
- 简单介绍SQL Server中索引使用及维护
- 简单东西-SpringMVC注入Bean的简单知识
- 【Serious Game】笔记1
- Java NIO、NIO.2学习笔记
- OC 解决NSArray、NSDictionary直接打印中文出现乱码的问题
- 控制台IO操作函数
- nginx---配置文件中根据来源IP,定向访问
- [开心学php100天]第五天:与基本功搞一搞基(上)
- UDP广播原理简介
- Eclipse或MyEclipse不能编译java文件
- ABAP中ALV使用HTML的例子
- 【基础练习】n&1==0错在哪儿?
- LoadLibrary ErrCode=193 %1 不是合法的Win32 应用程序
- 快速排序各种版本(record)