cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : manipulators : setbase
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
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

-

setbase manipulator function
smanip setbase ( int base );
<iomanip>

Set basefield flag

Sets the basefield format flag to one of its possible values: hex, dec or oct depending on the value of the base parameter.

The basefield flag is used in certain input and output operations to determine the numeric base to be used to interpret numeric values.

This manipulator is declared in header <iomanip>, along with the other parameterized manipulators: resetiosflags, setiosflags, setfill, setprecision and setw. This header file declares the implementation-specific smanip type, plus any additional operator overload function needed to allow these manipulators to be inserted and extracted to/from streams with their parameters.

Parameters

base
Numerical radix to be used.
This value should be 8, 10 or 16.

Return Value

Unspecified. This function should only be used as a stream manipulator.

Example

// setbase example
#include <iostream>
#include <iomanip>
using namespace std;

int main () {
  cout << setbase (16);
  cout << 100 << endl;
  return 0;
}

This code uses the setbase manipulator to set hexadecimal as the basefield flag. The output of this example is the hexadecimal value of 100, i.e. 64.

See also

oct Use octal base (manipulator function)
dec Use decimal base (manipulator function)
hex Use hexadecimal base (manipulator function)
ios_base::flags Get/set format flags (public member function)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us