C++ Manipulator setbaseC++ manipulator setbase is used to convert the basefield of one numeric value into another base. Possible values are: dec: decimal base (base = 10) hex: hexadecimal base (base = 16) oct: octal base (base = 8) zero: If base is any other value. In addition to the base conversion the setbase manipulator is also used to define the base of the numeral value of a variable. The original default of stream input and output is dec. SyntaxParameterbase: Numerical radix to be used as given below: 8 - oct 10- dec 16- hex Any other - resetiosflags(ios_base:: basefield) Return valueReturn ValueThis function returns an object of unspecified type. setbase function should only be used as a stream manipulator. Data RacesThe stream object on which it is inserted or extracted is modified and concurrent access to the same stream object may introduce data races. ExceptionsObject is in a valid state, if any exception is thrown. Example 1Let's see the simple example to demonstrate the use of setbase: Output: 6e Example 2Let's see another simple example: Output: Parsing string "10 0x10 010" hexadecimal parse: 16 16 16 prefix-dependent parse: 10 16 8 hex output: 0xa 0x10 0x8 Example 3Let's see another simple example to show the base of a numeric value of a variable using hex, oct, dec manipulator: Output: Enter number 11 Decimal base = 11 Hexadecimal base = b Octal base = 13 Example 4Let's see another simple example to show the base of a numeric value of a variable using setbase manipulator function: Output: Enter number 11 Decimal base = 11 Hexadecimal base = b Octal base = 13
Next TopicC++ Manipulator
|