
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ iomanip Library - setbases Function
Description
The C++ function std::setbases behaves as if setf(which,ios_base::basefield) were called on the stream on which it is inserted/extracted as a manipulator, with which being −
dec, if base is 10
hex, if base is 16
oct, if base is 8
zero, if base is any other value.
It is used to sets the basefield to one of its possible values: dec, hex or oct, according to argument base.
Declaration
Following is the declaration for std::setbases function.
setbase (int base);
Parameters
base − Numerical radix to be used as shown below −
base − Numerical radix to be used as shown below −
Sr.No. | base argument & same as inserting |
---|---|
1 | 8 oct |
2 | 10 dec |
3 | 16 hex |
4 | any other resetiosflags(ios_base::basefield) |
Return Value
It returns unspecified. This function should only be used as a stream manipulator.
Exceptions
Basic guarantee − if an exception is thrown, the stream is in a valid state.
Data races
The stream object on which it is inserted/extracted is modified. Concurrent access to the same stream object may introduce data races.
Example
In below example explains about setbase function.
#include <iostream> #include <iomanip> int main () { std::cout << std::setbase(16); std::cout << 110 << std::endl; return 0; }
Let us compile and run the above program, this will produce the following result −
6e