3
/ ++
- / cin cout.
.
- ++ -, . , / . / / ++ cin cout , /.
, - C++, <iostream>:
#include <iostream>
using namespace std;
<iomanip>
#include <iomanip>
. .
// -: cout.fill('/*symbol*/'); // // symbol- , cout.width(/*width_field*/); // // width_field - ( ) cout.precision(/*number*/); // - . // number - |
, . fill() , , ( ). /, ++ .
/. /, setf(), , unsetf(). .
// cout.setf(ios::/*name_flag*/); // name_flag - |
. setf() . ios, , , , ios, , , .
// cout.unsetf(ios::/*name_flag*/); // name_flag - |
/ () , |. C++ :
|
|
// cout.setf(ios::/*name_flag1*/|ios::/*name_flag2*/|ios::/*name_flag_n*/); // cout.unsetf(ios::/*name_flag1*/|ios::/*name_flag2*/|ios::/*name_flag_n*/); |
1 , .
1 ++ | |||
boolalpha | (true, false) | cout.setf(ios::boolalpha); bool log_false = 0, log_true = 1; cout << log_false << endl << log_true << endl; | false true |
oct | / ( dec, oct) | cout.unsetf(ios::dec); cout.setf(ios::oct); int value; cin >> value; cout << value << endl; | :9910 :1438 |
dec | / ( ) | cout.setf(ios::dec); int value = 148; cout << value << endl; | |
hex | / ( dec, hex) | cout.unsetf(ios::dec); cout.setf(ios::hex); int value; cin >> value; cout << value << endl; | :9910 :6316 |
showbase | cout.unsetf(ios::dec); cout.setf(ios::oct | ios::showbase); int value; cin >> value; cout << value << endl; | :9910 :01438 | |
uppercase | ( ) | cout.unsetf(ios::dec); cout.setf(ios::hex | ios::uppercase); int value; cin >> value; cout << value << endl; | :25510 :FF16 |
showpos | + | cout.setf(ios::showpos); int value = 15; cout << value << endl; | +15 |
scientific | cout.setf(ios::scientific); double value = 1024.165; cout << value << endl; | 1.024165e+003 | |
fixed | ( ) | double value = 1024.165; cout << value << endl; | 1024.165 |
right | ( ). ( , ). | cout.width(40); cout << khai.edu<< endl; | __khai.edu |
left | . ( , ). | cout.setf(ios::left); cout.width(40); cout << khai.edu << endl; | khai.edu__ |
. , /, . , /. , , . , , . ++ /. 2 ++.
|
|
2 ++ | |||
endl | cout << website: << endl << khai.edu; | website: khai.edu | |
boolalpha | (true, false) | bool log_true = 1; cout << boolalpha << log_true << endl; | true |
noboolalpha | (true, false) | bool log_true = true; cout << noboolalpha << log_true << endl; | |
oct | int value = 64; cout << oct << value << endl; | 1008 | |
dec | ( ) | int value = 64; cout << dec << value << endl; | 6410 |
hex | int value = 64; cout << hex << value << endl; | 408 | |
showbase | int value = 64; cout << showbase << hex << value << endl; | 0x40 | |
noshowbase | ( ). | int value = 64; cout << noshowbase << hex << value << endl; | |
uppercase | ( ). | int value = 255; cout << uppercase << hex << value << endl; | FF16 |
nouppercase | ( ). | int value = 255; cout << nouppercase << hex << value << endl; | ff16 |
showpos | + | int value = 255; cout << showpos<< value << endl; | +255 |
noshowpos | + ( ). | int value = 255; cout <<noshowpos<< value << endl; | |
scientific | double value = 1024.165; cout << scientific << value << endl; | 1.024165e+003 | |
fixed | . | double value = 1024.165; cout << fixed << value << endl; | 1024.1650 |
defaultfloat | . | double value = 1024.165; cout << defaultfloat << value << endl; | 1024.165 |
setw(int number) | , number , ( ). . | cout << setw(40) << khai.edu << endl; | __khai.edu |
right | ( ). ( , ). | cout << setw(40) << right << khai.edu << endl; | __khai.edu |
left | . ( , ). | cout << setw(40) << left << khai.edu << endl; | khai.edu__ |
setprecision(int count) | , count | cout << fixed << setprecision(3) << (13.5 / 2) << endl; | 6.750 |
setfill(int symbol) | . , , symbol | cout << setfill(0′) << setw(4) << 15 << ends << endl; |
|
|
( ) , :
- ( ) (. )
, .
- .
- / cin cout.
- , ( ) .
True False True True False True True False False True True False False True True False True False False True False True False False True True |