2018年6月29日 星期五

I/O控制

#include
 cout << oct << 50 << endl    // 8進位顯示 
         << hex << 50 << endl;   // 16進位顯示 
順理推之,oct,hex,dec在include 之後
boolalpha 可以讓原本顯示的1,0變成以true,false顯示
int main() { 
    bool boolnum; 

    boolnum = true; 
    cout << boolalpha << boolnum << endl; 

    boolnum = false; 
    cout << boolalpha << boolnum << endl; 

    return 0; 
}
boolalpha讓bool輸出時顯示true與false
dec10進位顯示 
endl 輸出new line字元
ends輸出Null字元
fixed以正常的數字格式顯示
flush清除串流 
hex16進位顯示
left靠左對齊
oct8進位顯示
right靠右顯示
scientific科學記號表示 
setbase(int b)指定數字基底
setfill(int c)指定填充字元
setprecision(int p)指定顯示精確度
setw(int w) 指定欄位寬度,並以16進位顯示
showbase 顯示數字基底,例如0x11
showpoint 顯示小數
showpos正數顯示+號
skipws忽略輸入的空白字元
upperbase字母大寫
ws忽略前導的空白字元
noboolalpha關閉boolalpha的使用 
noshowbase關閉showbase的使用
noshowpoint關閉showpoint的使用 
noshowpos 關閉showpos的使用
noskipws關閉skipws的使用 
nouppercase關閉uppercase的使用

cout.unsetf(ios::dec); // 取消10進位顯示 
    cout.setf(ios::hex | ios::scientific); // 16進位顯示或科學記號顯示 
 cout.setf(ios::showpos | ios::showpoint); // 正數顯示 + 號且顯示小數點 

沒有留言:

張貼留言

Ethereum- Learn Solidity step by step

Common Function Types: public: Anyone can call this function,but it isn't really used for any type of security per se. priv...