/*unspecified*/ setbase( int base );
Sets the numeric base of the stream. When used in an expression out << setbase(base) or in >> setbase(base), changes the basefield
flag of the stream out or in, depending on the value of base:
basefield
to std::ios_base::hex.Values of base other than 8, 10, or 16 reset basefield
to zero, which corresponds to decimal output and prefix-dependent input.
An object of unspecified type such that
where the function f is defined as:
[edit] Example#include <iomanip> #include <iostream> #include <sstream> int main() { std::cout << "Parsing string \"10 0x10 010\"\n"; int n1, n2, n3; std::istringstream s("10 0x10 010"); s >> std::setbase(16) >> n1 >> n2 >> n3; std::cout << "hexadecimal parse: " << n1 << ' ' << n2 << ' ' << n3 << '\n'; s.clear(); s.seekg(0); s >> std::setbase(0) >> n1 >> n2 >> n3; std::cout << "prefix-dependent parse: " << n1 << ' ' << n2 << ' ' << n3 << '\n'; std::cout << "hex output: " << std::setbase(16) << std::showbase << n1 << ' ' << n2 << ' ' << n3 << '\n'; }
Output:
Parsing string "10 0x10 010" hexadecimal parse: 16 16 16 prefix-dependent parse: 10 16 8 hex output: 0xa 0x10 0x8[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 183 C++98setbase
could only be used with streams
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4