std::setbase

Header: <iomanip>

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:

# Declarations

/*unspecified*/ setbase( int base );

# Parameters

# Return value

An object of unspecified type such that

# 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';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 183C++98setbase could only be used with streamsof type std::ostream or std::istreamusable with anycharacter stream

# See also