프로그래밍

[C++] string format

하루삼십만원 2020. 10. 12. 19:41
반응형

[C++] string format

 

오늘은 서식 지정에 관련된 내용입니다. I/O stream 의 헤더 파일 <iomanip>를  include하여 서식을 지정할 수 있습니다.

 

아래 method를 이용하면 나에게 맞는 format으로 출력이 가능합니다.

 

각 method별 설명은 아래와 같습니다.

 

setprecision() : Sets the decimal precision to be used to format floating-point values on output operations.

setw() : Sets the field width to be used on output operations.

setfill() : Sets c as the stream's fill character.

scientific() : Sets the floatfield format flag for the str stream to scientific.

 

oct() : Sets the basefield format flag for the str stream to oct.
hex() : Sets the basefield format flag for the str stream to hex.
dec() : Sets the basefield format flag for the str stream to dec.

 

boolalpha() : Sets the boolalpha format flag for the str stream.
noboolalpha() : Clears the boolalpha format flag for the str stream.
unsetf() : Clears the format flags selected in mask.

 

 

샘플 코드를 실행해 보면 아래와 같은 결과를 확인할 수 있습니다.

 

반응형

'프로그래밍' 카테고리의 다른 글

[C++] shared_ptr, weak_ptr  (0) 2020.10.18
[C++] unique_ptr  (0) 2020.10.17
[C++] write string with ostream, stringstream class  (0) 2020.10.11
[C++] File input/output  (0) 2020.10.11
Support C++ Standard in Visual Studio  (0) 2020.10.09