C++ iomanip setbase() Function
Example
Print the number 255 in base 16 (hexadecimal) and base 8 (octal):
cout << setbase(16) << 255 << "\n";
cout << setbase(8) << 255;
Definition and Usage
The setbase() function sets the number base that is used to print whole numbers.
Use 16 for hexadecimal, 8 for octal, and 10 for normal (decimal) numbers.
The setbase function is defined in the <iomanip> header file.
Syntax
setbase(int base)
Parameter Values
| Parameter | Description |
|---|---|
| base | Required. The number base: 8, 10 or 16. Other values print normal decimal numbers. |
Technical Details
| Returns: | A manipulator that you use with <<. It changes all the whole numbers printed after it. |
|---|