Skip to content

Std::ios base

openmode

(std::ios_base::openmode로도 접근 가능)

typedef /*implementation defined*/ openmode;
// ...
static constexpr openmode app = /*implementation defined*/
static constexpr openmode binary = /*implementation defined*/
static constexpr openmode in = /*implementation defined*/
static constexpr openmode out = /*implementation defined*/
static constexpr openmode trunc = /*implementation defined*/
static constexpr openmode ate = /*implementation defined*/

Specifies available file open flags. It is a BitmaskType, the following constants are defined:

Constant

Explanation

app

seek to the end of stream before each write

binary

open in binary mode

in

open for reading

out

open for writing

trunc

discard the contents of the stream when opening

ate

seek to the end of stream immediately after open

fmtflags consts

Constant

Explanation

dec

use decimal base for integer I/O: see std::dec

oct

use octal base for integer I/O: see std::oct

hex

use hexadecimal base for integer I/O: see std::hex

basefield

dec|oct|hex|0. Useful for masking operations

left

left adjustment (adds fill characters to the right): see std::left

right

right adjustment (adds fill characters to the left): see std::right

internal

internal adjustment (adds fill characters to the internal designated point): see std::internal

adjustfield

left|right|internal. Useful for masking operations

scientific

generate floating point types using scientific notation, or hex notation if combined with fixed: see std::scientific

fixed

generate floating point types using fixed notation, or hex notation if combined with scientific: see std::fixed

floatfield

scientific|fixed|(scientific|fixed)|0. Useful for masking operations

boolalpha

insert and extract bool type in alphanumeric format: see std::boolalpha

showbase

generate a prefix indicating the numeric base for integer output, require the currency indicator in monetary I/O: see std::showbase

showpoint

generate a decimal-point character unconditionally for floating-point number output: see std::showpoint

showpos

generate a + character for non-negative numeric output: see std::showpos

skipws

skip leading whitespace before certain input operations: see std::skipws

unitbuf

flush the output after each output operation: see std::unitbuf

uppercase

replace certain lowercase letters with their uppercase equivalents in certain output output operations: see std::uppercase

precision

// modify precision
#include <iostream> // std::cout, std::ios

int main () {
  double f = 3.14159;
  std::cout.unsetf ( std::ios::floatfield );                // floatfield not set
  std::cout.precision(5);
  std::cout << f << '\n';
  std::cout.precision(10);
  std::cout << f << '\n';
  std::cout.setf( std::ios::fixed, std:: ios::floatfield ); // floatfield set to fixed
  std::cout << f << '\n';
  return 0;
}

Output:

3.1416
3.14159
3.1415900000

Notice how the first number written is just 5 digits long, while the second is 6, but not more, even though the stream's precision is now 10. That is because precision with the default floatfield only specifies the maximum number of digits to be displayed, but not the minimum. The third number printed displays 10 digits after the decimal point because the floatfield format flag is in this case set to fixed.

See also