C++ standard output에 대해서 알아보겠습니다.
조정자(Manipulator)
#include <iostream> 안에 있는 조정자
- showbase/noshowbase
- showpos/noshowpos (pos -> positive)
- dec(decimal)
- hex(hexa decimal)
- oct(octal decimal)
- uppercase/noupeercase
- left/internal/right
- showpoint/noshowpoint
- fixed/scientific
- boolalpha / noboolalpha
- setw(n)
- setfill(char형)
빈공간의 char형 문자를 채우기
- setprecision(n)
//실행 예제 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <iostream> #include <iomanip> using namespace std; int main() { int num = 1234; cout << showbase << dec << num << endl; //1234 cout << showbase << oct << num << endl; //02322 cout << showbase << hex << num << endl; //0x4d2 cout << noshowbase << dec << endl; //초기화&줄맞춤 cout << showpos << num << endl; //+1234 cout << noshowpos << num << endl; //1234 cout << endl; //줄맞춤 cout << uppercase << hex << num << endl; //4D2 cout << nouppercase << hex << num << endl; //4d2 cout << noshowbase << dec << endl; //초기화&줄맞춤 cout << setw(6) << left << -num << endl; //-1234 cout << setw(6) << internal << -num << endl;//- 1234 cout << setw(6) << right << -num << endl; // -1234 cout << endl; //줄맞춤 float decimal1 = 10.0f; float decimal2 = 10.12f; cout << noshowpoint << decimal1 << " " << decimal2 << endl; //10 10.12 cout << showpoint << decimal1 << " " << decimal2 << endl; //10.0000 10.1200 cout << fixed << decimal2 << endl; //10.120000 cout << scientific << decimal2 << endl; //1.012000e+01 bool boolean = true; cout << fixed << endl; //줄맞춤 cout << boolalpha << boolean << endl; //true cout << noboolalpha << boolean << endl; //1 cout << endl; //줄맞춤 cout << setfill('*') << setw(6) << num << endl; //**1234 cout << endl; //줄맞춤 cout << setprecision(7) << decimal2 << endl; //10.1199999 system("pause"); return 0; } | cs |
'프로그래밍 > C++' 카테고리의 다른 글
C++ namespace/using (0) | 2019.01.02 |
---|