std:: dec, std:: hex, std:: oct
|
헤더 파일에 정의됨
<ios>
|
||
|
std::
ios_base
&
dec
(
std::
ios_base
&
str
)
;
|
(1) | |
|
std::
ios_base
&
hex
(
std::
ios_base
&
str
)
;
|
(2) | |
|
std::
ios_base
&
oct
(
std::
ios_base
&
str
)
;
|
(3) | |
정수 I/O에 대한 기본 숫자 진법을 수정합니다.
basefield
를
dec
로 설정합니다. 마치
str.
setf
(
std::
ios_base
::
dec
,
std::
ios_base
::
basefield
)
를 호출한 것처럼 동작합니다.
basefield
를
hex
로 설정합니다. 마치
str.
setf
(
std::
ios_base
::
hex
,
std::
ios_base
::
basefield
)
를 호출한 것처럼 동작합니다.
basefield
를
oct
로 설정합니다. 마치
str.
setf
(
std::
ios_base
::
oct
,
std::
ios_base
::
basefield
)
를 호출한 것처럼 동작합니다.
이것은 I/O 조정자입니다. 다음과 같은 표현식으로 호출될 수 있습니다:
out
<<
std
::
hex
(여기서
out
은
std::basic_ostream
타입의 객체), 또는 다음과 같은 표현식으로 호출될 수 있습니다:
in
>>
std
::
hex
(여기서
in
은
std::basic_istream
타입의 객체).
목차 |
매개변수
| str | - | I/O 스트림에 대한 참조 |
반환값
str (조작 후 스트림에 대한 참조).
예제
#include <bitset> #include <iostream> #include <sstream> int main() { std::cout << "The number 42 in octal: " << std::oct << 42 << '\n' << "The number 42 in decimal: " << std::dec << 42 << '\n' << "The number 42 in hex: " << std::hex << 42 << '\n'; int n; std::istringstream("2A") >> std::hex >> n; std::cout << std::dec << "Parsing \"2A\" as hex gives " << n << '\n'; // the output base is sticky until changed std::cout << std::hex << "42 as hex gives " << 42 << " and 21 as hex gives " << 21 << '\n'; // Note: there is no I/O manipulator that sets up a stream to print out // numbers in binary format (e.g. bin). If binary output is necessary // the std::bitset trick can be used: std::cout << "The number 42 in binary: " << std::bitset<8>{42} << '\n'; }
출력:
The number 42 in octal: 52 The number 42 in decimal: 42 The number 42 in hex: 2a Parsing "2A" as hex gives 42 42 as hex gives 2a and 21 as hex gives 15 The number 42 in binary: 00101010
참고 항목
|
정수 I/O에 사용되는 진법을 변경합니다
(function) |
|
|
숫자 진법을 나타내는 접두사 사용 여부를 제어합니다
(function) |