?? 11-2.txt
字號(hào):
/* 范例:11-2 標(biāo)志 */
#include <iostream.h>
void main(void)
{
int a = 68, b = 38, c = 6;
cout.setf(ios::showpos); // 當(dāng) >=0 顯示'+'號(hào)
/* 對(duì)齊控制 */
cout << "/* 對(duì)齊控制: */ " <<endl;
cout.width(10); // 設(shè)定寬度為10
cout.setf(ios::left);
cout << a << "\n";
cout.unsetf(ios::left); // #1.1 清除同一組靠左對(duì)齊設(shè)定
cout.setf(ios::right); // #1.2 設(shè)定同一組靠右對(duì)齊設(shè)定
cout.width(10);
cout << b << endl;
cout.unsetf(ios::adjustfield); // #2 取消對(duì)齊
cout.width(10);
cout << c << "\n\n";
/* 布爾 */
cout << "/* 布爾: */" << endl;
cout << "布爾常數(shù) true = " << true << endl;
cout.setf(ios::boolalpha);
cout << "設(shè)定 boolalpha 后,布爾常數(shù) true = " << true << endl;
// -----------------------------------------------------------
float f = 5.680;
int k = 24;
cout.setf(ios::showpoint); // 顯示小數(shù)點(diǎn)
cout.setf(ios::showpos); // 當(dāng) >=0 顯示'+'號(hào)
cout.precision(3); // 設(shè)定浮點(diǎn)數(shù)精確度
cout.setf(ios::showbase); // 完全顯示幾進(jìn)制(0x,0)
cout.setf(ios::uppercase); // 轉(zhuǎn)換16進(jìn)位數(shù)值時(shí),A~F以大寫顯示
/* 進(jìn)位制控制 */
cout << "/* 進(jìn)位制控制: */" << endl;
cout.setf(ios::hex, ios::basefield); // #3 設(shè)定以16進(jìn)制顯示
cout << "十進(jìn)制 k = 24 十六進(jìn)制 k = " << k << endl;
cout.setf(ios::oct, ios::basefield); // 設(shè)定以8進(jìn)制顯示
cout << "十進(jìn)制 k = 24 八進(jìn)位 k = " << k << endl;
cout.setf(ios::dec, ios::basefield); // 設(shè)定以10進(jìn)制顯示
/* 浮點(diǎn)數(shù)顯示控制 */
cout << "/* 浮點(diǎn)數(shù)顯示控制: */" << endl;
cout.precision(3); // 設(shè)定精度有效3位
cout.setf(ios::fixed); // 設(shè)定以fixed符號(hào)輸出
cout << f << endl; // +5.680
cout.setf(ios::scientific,ios::floatfield); // 以科學(xué)記號(hào)表示
cout << f << endl; // +5.680E+00
/* 使用fill()成員函數(shù) */
cout << "使用fill()成員函數(shù)" << endl;
cout.fill('#'); // 設(shè)定輸出寬度內(nèi)空白填入字符'#'
cout.width(10); // # 4
cout << 24 << endl;
cout.fill('\0'); // # 5
cout.width(10);
cout << 24 << endl;
getchar();
}
程序執(zhí)行結(jié)果:
/* 對(duì)齊控制: */
+68
+38
+6
/* 布爾: */
布爾常數(shù) true = 1
設(shè)定 boolalpha 后,布爾常數(shù) true = true
/* 進(jìn)位制控制: */
十進(jìn)制 k = 24 十六進(jìn)制 k = 0X18
十進(jìn)制 k = 24 八進(jìn)位 k = 030
/* 浮點(diǎn)數(shù)顯示控制: */
+5.680
+5.680E+00
使用fill()成員函數(shù)
#######+24
+24
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -