?? 例13.3.txt
字號(hào):
例13.3 用流控制成員函數(shù)輸出數(shù)據(jù)。
#include <iostream>
using namespace std;
int main( )
{int a=21
cout.setf(ios::showbase);//顯示基數(shù)符號(hào)(0x或0)
cout<<″dec:″<<a<<endl; //默認(rèn)以十進(jìn)制形式輸出a
cout.unsetf(ios::dec); //終止十進(jìn)制的格式設(shè)置
cout.setf(ios::hex); //設(shè)置以十六進(jìn)制輸出的狀態(tài)
cout<<″hex:″<<a<<endl; //以十六進(jìn)制形式輸出a
cout.unsetf(ios::hex); //終止十六進(jìn)制的格式設(shè)置
cout.setf(ios::oct); //設(shè)置以八進(jìn)制輸出的狀態(tài)
cout<<″oct:″<<a<<endl; //以八進(jìn)制形式輸出a
cout.unseft(ios::oct);
char *pt=″China″; //pt指向字符串″China″
cout.width(10); //指定域?qū)挒?0
cout<<pt<<endl; //輸出字符串
cout.width(10); //指定域?qū)挒?0
cout.fill(′*′); //指定空白處以′*′填充
cout<<pt<<endl; //輸出字符串
double pi=22.0/7.0; //輸出pi值
cout.setf(ios::scientific); //指定用科學(xué)記數(shù)法輸出
cout<<″pi=″; //輸出″pi=″
cout.width(14); //指定域?qū)挒?4
cout<<pi<<endl; //輸出pi值
cout.unsetf(ios::scientific); //終止科學(xué)記數(shù)法狀態(tài)
cout.setf(ios::fixed); //指定用定點(diǎn)形式輸出
cout.width(12); //指定域?qū)挒?2
cout.setf(ios::showpos); //正數(shù)輸出“+”號(hào)
cout.setf(ios::internal); //數(shù)符出現(xiàn)在左側(cè)
cout.precision(6); //保留6位小數(shù)
cout<<pi<<endl; //輸出pi,注意數(shù)符“+”的位置
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -