This function is used to set the base to octal, decimal or hexadecimal. It sets the basefield format flag for the str stream to the specified base
std::oct : When basefield is set to octal, integer values inserted into the stream are expressed in octal base (i.e., radix 8). For input streams, extracted values are also expected to be expressed in octal base when this flag is set.
std::hex : When basefield is set to hex, integer values inserted into the stream are expressed in hexadecimal base (i.e., radix 16). For input streams, extracted values are also expected to be expressed in hexadecimal base when this flag is set.
The basefield format flag can take decimal values (each with its own manipulator). This is an I/O manipulator. It may be called with an expression such as out << std::oct, std::hex or std ::dec for any out of type std::basic_ostream or with an expression
ios_base& hex (ios_base& str); str : Stream object whose basefield format flag is affected. Return value : Return the augmented string parsed in the base decimal to base octal
Input : 54 Output : oct - 66 dec - 54 hex - 36
oct - 66 dec - 54 hex - 36
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- isupper() and islower() and their application in C++
- fesetround() and fegetround() in C++ and their application
- Queries to insert, delete one occurrence of a number and print the least and most frequent element
- Get first and last elements from Array and Vector in CPP
- Similarities and Differences between Ruby and C++
- Generate an array of given size with equal count and sum of odd and even numbers
- Similarities and Difference between Java and C++
- INT_MAX and INT_MIN in C/C++ and Applications
- Change/add only one character and print '*' exactly 20 times
- Comma in C and C++
- How does "void *" differ in C and C++?
- What are the operators that can be and cannot be overloaded in C++?
- Data type of character constants in C and C++
- Can we use function on left side of an expression in C and C++?
- delete and free() in C++
- ASCII NUL, ASCII 0 ('0') and Numeric literal 0
- Inheritance and friendship
- Type difference of character literals in C and C++
- Result of comma operator as l-value in C and C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.