C++ ios Library - Showbase Function


Advertisements

Description

It is used to sets the showbase format flag for the str stream. When the showbase format flag is set, numerical integer values inserted into output streams are prefixed with the same prefixes used by C++ literal constants: 0x for hexadecimal values (see hex), 0 for octal values (see oct) and no prefix for decimal-base values (see dec).

Declaration

Following is the declaration for std::showbase function.

ios_base& showbase (ios_base& str);

Parameters

str − Stream object whose format flag is affected.

Return Value

It returns Argument str.

Exceptions

Basic guarantee − if an exception is thrown, str is in a valid state.

Data races

It modifies str. Concurrent access to the same stream object may cause data races.

Example

In below example explains about std::showbase function.

#include <iostream>

int main () {
   int n = 20;
   std::cout << std::hex << std::showbase << n << '\n';
   std::cout << std::hex << std::noshowbase << n << '\n';
   return 0;
}

Let us compile and run the above program, this will produce the following result −

0x14
14
ios.htm
Advertisements