output stream
C++은 printf와 다른 출력 형식을 지정하는데 이걸 알아보도록 해봅시다.
[code]
// 진법 형식에 따라 결과 값일 변경된다. oct, hex, dec가 이에 속한다.
cout << "8진수 : " << oct << i << endl;
cout << "16진수 : " << hex << i << endl;
cout << "10진수 : " << dec << i << endl;
// 출력되는 폭을 지정한다
cout.width(10);
cout << i << endl;
// 문자를 채운다
cout.fill('_');
// 정렬을 지정한다.
cout << left << j << endl;
cout << right << j << endl;
cout << internal << j << endl;
// 실수의 정밀도 지정
cout.precision(3);
// 실수 출력 방식
cout << fixed << d << endl;
cout << scientific << d << endl;
// bool형 출력 방식
cout << b << endl;
cout << boolalpha << b << endl;
// 진법 접두 출력 및 대소문자
cout << hex << i << endl;
cout << showbase << i << endl;
cout << uppercase << i << endl;
// + 양수 기호 표시
cout << dec << showpos << i << endl;
[/code]
C++은 printf와 다른 출력 형식을 지정하는데 이걸 알아보도록 해봅시다.
[code]
// 진법 형식에 따라 결과 값일 변경된다. oct, hex, dec가 이에 속한다.
cout << "8진수 : " << oct << i << endl;
cout << "16진수 : " << hex << i << endl;
cout << "10진수 : " << dec << i << endl;
// 출력되는 폭을 지정한다
cout.width(10);
cout << i << endl;
// 문자를 채운다
cout.fill('_');
// 정렬을 지정한다.
cout << left << j << endl;
cout << right << j << endl;
cout << internal << j << endl;
// 실수의 정밀도 지정
cout.precision(3);
// 실수 출력 방식
cout << fixed << d << endl;
cout << scientific << d << endl;
// bool형 출력 방식
cout << b << endl;
cout << boolalpha << b << endl;
// 진법 접두 출력 및 대소문자
cout << hex << i << endl;
cout << showbase << i << endl;
cout << uppercase << i << endl;
// + 양수 기호 표시
cout << dec << showpos << i << endl;
[/code]
'Native > C++' 카테고리의 다른 글
ios_base (Base class with template-independent members for the standard stream class hierarchy) (0) | 2013.10.02 |
---|---|
c++ classes for input and output operations (0) | 2013.10.02 |
실시간 타입 정보(don (0) | 2013.10.02 |
C++관련 연산자 이용방법 예제 (0) | 2013.10.02 |
간단하게 짠 연산자 소스 (operator) (0) | 2013.10.02 |