Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
filebuf
fstream
ifstream
ios
iostream
ios_base
istream
istringstream
ofstream
ostream
ostringstream
streambuf
stringbuf
stringstream
objects:
cerr
cin
clog
cout
types:
fpos
streamoff
streampos
streamsize
manipulators
boolalpha
dec
endl
ends
fixed
flush
hex
internal
left
noboolalpha
noshowbase
noshowpoint
noshowpos
noskipws
nounitbuf
nouppercase
oct
resetiosflags
right
scientific
setbase
setfill
setiosflags
setprecision
setw
showbase
showpoint
showpos
skipws
unitbuf
uppercase
ws


oct

manipulator function
<ios>
ios_base& oct ( ios_base& str );

Use octal base

Sets the basefield format flag for the str stream to oct.

When basefield is set to oct, integral numerical values inserted into the stream are expressed in the octal base (radix 8). For input streams, extracted values are also expected to be expressed in the octal base when this flag is set.

The basefield format flag can take any of the following values (each with its own manipulator):

flag valueeffect when set
decread/write integral values using decimal base format.
hexread/write integral values using hexadecimal base format.
octread/write integral values using octal base format.

The basefield flag is set to dec in standard streams on initialization.

Notice that the basefield flag only affects the insertion/extraction of integer values. Floating-point values are always treated in the decimal base.

Notice also that no base prefix is implicitly prepended to the number unless the showbase format flag is set.

Parameters

str
Stream object where to apply.
Because this function is a manipulator, it is designed to be used alone with no arguments in conjunction with the insertion (<<) and extraction (>>) operations on streams (see example below).

Return Value

A reference to the stream object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// modify basefield
#include <iostream>
using namespace std;
int main () {
  int n;
  n=70;
  cout << oct << n << endl;
  cout << dec << n << endl;
  cout << hex << n << endl;
  return 0;
}


The execution of this example displays something similar to:
106
70
46

See also