Use ostream with bases other than 8, 10 and 16
I have a polynomial class, and its natural representation is its coefficients. If a coefficient is set, then its a 1 for binomial basis, 1 or 2 for trinomial basis, etc. For example, in a binomial basis, X2 + 1 is represented as 101; and in a trinomial basis, 2X2 + 1 is represented as 201.
The class provides an operator<<
overload. Internally, the class represents the coefficients using an integral array. So I should be able to perform:
ostringstream oss;
for (size_t i=0; i<v.size(); i++)
oss << v[i];
The problem I am having is I don't know how to configure the ostream for bases other than 8, 10 and 16. ios_base
provides std::oct
, std::dec
and std::hex
for the popular bases, but I don't see what to use for the less frequently used bases. And pages like C++ Reference on ios_base does not discuss what to use.
How do I use ostream with bases other than 8, 10 and 16?
I don't think this is possible using standard means. Looking at std::setbase
Values of base other than 8, 10, or 16 reset basefield to zero, which corresponds to decimal output and prefix-dependent input.
Replacing my answer since the direction was backwards. See itoa. The documentation says that it is a non standard function. Since this is a non standard function, stackoverflow has some implementations in the page.
链接地址: http://www.djcxy.com/p/88806.html上一篇: 为什么R无法加载共享对象?