answersLogoWhite

0

The std::setbase (int base) function is a stream manipulator function which sets the stream's basefield to octal, decimal or hexadecimal depending on the value of the baseargument.

Example usage:

int n = 42;

std::cout << std::setbase (16) << n << std::endl;

The output would be:

2a

When applied to an output stream, integer values will be inserted in the specified format. When applied to an input stream, integers extracted from the stream will be expected to be in the specified format.

Note that std::setbase (base) behaves exactly the same as std::setf (which, ios_base::basefield), with whichbeing:

std::oct, if base is 8

std::dec, if base is 10

std::hex, if base is 16

As such, std::setbase provides a shorthand alternative to the more verbose std::setf manipulator.

User Avatar

Wiki User

7y ago

What else can I help you with?