티스토리 뷰

c++

출력 (Output)

길 킴 2019. 8. 7. 22:08
728x90

출력 (Output)

  1. 조정자
    1. cout
      1. showbase : 몇진법인지 표기
        cout << showbase << hex << number << endl; //0x7b
      2. showpos / noshowpos  : 양수일 때 플러스 표기 (positive number)
      3. dec / hex / oct : 10진법, 16진수, 8진수 (옥탈)
      4. uppercase / nouppercase
        cout << uppercase << hex << number; //7B
      5. 정렬 관련 (left/ internal/ right)
        1. setw() : 컬럼 수 세팅
          cout << setw(6) << left << number; // |-123   |
          cout << setw(6) << internal << number; // |-      123|
          cout << setw(6) << right << number; // |     -123|
      1. showpoint / noshowpoint : 소수점 이하 표기 여부
        float decimal1 = 100.0; decimal2 = 100.12;
        cout << noshowpoint << decimal1 << " " << decimal2; // 100 100.12
        cout << showpoint << decimal1 << " " << decimal2; // 100.000 100.120
      2. fixed / scientific : 고정적 / 과학적 소수 표기법
        cout << fixed << number; // 123.456789
        cout << scientific << number; // 1.234568E+02
      3. boolalpha / noboolalpha 
        bool bReady = true;
        cout << boolalpha << bReady; // true
        cout << noboolalpha << bReady; // 1
    1. 몇몇 조정자를 쓰려면 필요한 인클루드
      #include <iomanip>
      1. setw() : 컬럼 수 세팅
      2. setfill(): 빈공간 특정 문자로 표기
        cout << setfill('*') << setw(5) << number; // **123
      3. setprecision(): 소수점 유효 자리 표기 (precision: 정확성)
        float number = 123.456789
        cout << setprecision(7) << number; // 123.456789
    2. size_t 타입 : 크기를 나타낼 때 (양수 값)
      const size_t myValue = 10;
    3. 조정자 설정하면 아래 cout에도 영향을 끼침
      cout << left << fixed << showpoint << setprecision(2); 
      cout << setfill('-') << setw(colLength + rowLength) << endl << setfill(' ); => setfill 다시 초기화 필요

<참고사항> (그리 많이 사용되지는 않음)
  1. setf() / unsetf() : 조정자 Flag 설정
    cout.setf(ios_base::showpos);  // 네임스페이스 ios_base를 쓴다. 
    cout<<number;
  2. width(), fill(), precision() 함수들이 있다. 
    cout.width(5);


'c++' 카테고리의 다른 글

입력  (0) 2019.08.07
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함