iomanip setbase() function in C++ with Examples
The setbase() method of iomaip library in C++ is used to set the ios library basefield flag based on the argument specified as the parameter to this method.
Syntax:
setbase (int base)
Parameters: This method accepts base as a parameter which is the integer argument corresponding to which the base is to be set. 10 stands for dec, 16 stands for hex, 8 stands for oct, and any other value stands for 0 (reset).
Return Value: This method does not returns anything. It only acts as stream manipulators.
Example 1:
// C++ code to demonstrate // the working of setbase() function #include <iomanip> #include <ios> #include <iostream> using namespace std; int main() { // Initializing the integer int num = 50; cout << "Before set: \n" << num << endl; // Using setbase() cout << "Setting base to hex" << " using setbase: \n" << setbase(16) << num << endl; return 0; } |
Before set: 50 Setting base to hex using setbase: 32
Example 2:
// C++ code to demonstrate // the working of setbase() function #include <iomanip> #include <ios> #include <iostream> using namespace std; int main() { // Initializing the integer int num = 50; cout << "Before set: \n" << num << endl; // Using setbase() cout << "Setting base to oct" << " using setbase: \n" << setbase(8) << num << endl; return 0; } |
Before set: 50 Setting base to oct using setbase: 62
Reference: http://www.cplusplus.com/reference/iomanip/setbase/
Recommended Posts:
- iomanip setfill() function in C++ with Examples
- iomanip resetiosflags() function in C++ with Examples
- iomanip setiosflags() function in C++ with Examples
- iomanip setpricision() function in C++ with Examples
- iomanip setw() function in C++ with Examples
- std::setbase, std::setw , std::setfill in C++
- ios eof() function in C++ with Examples
- ios bad() function in C++ with Examples
- ios fail() function in C++ with Examples
- quick_exit() function in C++ with Examples
- wcscmp() function in C++ with Examples
- ios operator !() function in C++ with Examples
- ios good() function in C++ with Examples
- ios setstate() function in C++ with Examples
- ios clear() function in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.



