Standard I/O Stream
C++的標準輸入/輸出庫 iostream
不僅提供了I/O庫,還提供了使用庫的流模式
" cin>>"流入和 " cout<<"流出到輸出設備的操作符
1.流狀態(tài) (Stream States)
1st showpos 在正數(shù)(含0)前顯示 + 號
2nd showbase HEX前加 0X,OCT前加 0
3rd uppercase HEX里字母大寫
4th showpoint 浮點輸出即使小數(shù)點后都為0也加小數(shù)點
5th boolalpha 邏輯值用true false
6th left 左對齊
7th right 右對齊
8th dec 十進制表示整數(shù)
9th hex 十六進制
10 oct 八進制
11 fixed 定點數(shù)格式輸出
12 scientific 科學記數(shù)法格式輸出
2.取消流狀態(tài)的操作
noshowpos noshowbase nouppercase noshowpoint noboolalpha
cout.unsetf(ios::scientific);
3.有參數(shù)的3個常用的流狀態(tài)
width(int) //設置顯示寬度
fill(char) //設置填充字符
precision(int) //設置有效位數(shù)
這些流狀態(tài)是以 cout 捆綁調(diào)用他們的形式設置的,不能與流出符 << 連用
特別注意 width(n)為一次性操作,既第二次顯示時將不再有效 default width(0)
example
cout.width(5);
cout.fill(’S’);
cout<<23<<23;
//SSS2323
4.與<<連用的設置方式
使用時,要包含頭文件 iomanip
setw(int)
setfill(char)
setprecision(int)
example
cout< 倒三角形例子
#include
#include
using namespace std;
void main()
{
for(int n=1;n<=10;++n)
cout< < }
另外使用string
#include
#include
using namespace std;
int main()
{
for(int n=1;n<=10;++n)
cout< }
C++的標準輸入/輸出庫 iostream
不僅提供了I/O庫,還提供了使用庫的流模式
" cin>>"流入和 " cout<<"流出到輸出設備的操作符
1.流狀態(tài) (Stream States)
1st showpos 在正數(shù)(含0)前顯示 + 號
2nd showbase HEX前加 0X,OCT前加 0
3rd uppercase HEX里字母大寫
4th showpoint 浮點輸出即使小數(shù)點后都為0也加小數(shù)點
5th boolalpha 邏輯值用true false
6th left 左對齊
7th right 右對齊
8th dec 十進制表示整數(shù)
9th hex 十六進制
10 oct 八進制
11 fixed 定點數(shù)格式輸出
12 scientific 科學記數(shù)法格式輸出
2.取消流狀態(tài)的操作
noshowpos noshowbase nouppercase noshowpoint noboolalpha
cout.unsetf(ios::scientific);
3.有參數(shù)的3個常用的流狀態(tài)
width(int) //設置顯示寬度
fill(char) //設置填充字符
precision(int) //設置有效位數(shù)
這些流狀態(tài)是以 cout 捆綁調(diào)用他們的形式設置的,不能與流出符 << 連用
特別注意 width(n)為一次性操作,既第二次顯示時將不再有效 default width(0)
example
cout.width(5);
cout.fill(’S’);
cout<<23<<23;
//SSS2323
4.與<<連用的設置方式
使用時,要包含頭文件 iomanip
setw(int)
setfill(char)
setprecision(int)
example
cout<
#include
#include
using namespace std;
void main()
{
for(int n=1;n<=10;++n)
cout<
另外使用string
#include
#include
using namespace std;
int main()
{
for(int n=1;n<=10;++n)
cout<

