Previous: Formatted Output Functions, Up: Formatted Output
The following functions are provided in libgmpxx (see Headers and Libraries), which is built if C++ support is enabled (see Build Options).
Prototypes are available from <gmp.h>.
Print op to stream, using its
iosformatting settings.ios::widthis reset to 0 after output, the same as the standardostream operator<<routines do.In hex or octal, op is printed as a signed number, the same as for decimal. This is unlike the standard
operator<<routines onintetc, which instead give twos complement.
Print op to stream, using its
iosformatting settings.ios::widthis reset to 0 after output, the same as the standardostream operator<<routines do.Output will be a fraction like `5/9', or if the denominator is 1 then just a plain integer like `123'.
In hex or octal, op is printed as a signed value, the same as for decimal. If
ios::showbaseis set then a base indicator is shown on both the numerator and denominator (if the denominator is required).
Print op to stream, using its
iosformatting settings.ios::widthis reset to 0 after output, the same as the standardostream operator<<routines do.The decimal point follows the standard library float
operator<<, which on recent systems means thestd::localeimbued on stream.Hex and octal are supported, unlike the standard
operator<<ondouble. The mantissa will be in hex or octal, the exponent will be in decimal. For hex the exponent delimiter is an `@'. This is as permpf_out_str.
ios::showbaseis supported, and will put a base on the mantissa, for example hex `0x1.8' or `0x0.8', or octal `01.4' or `00.4'. This last form is slightly strange, but at least differentiates itself from decimal.
These operators mean that GMP types can be printed in the usual C++ way, for example,
mpz_t z;
int n;
...
cout << "iteration " << n << " value " << z << "\n";
But note that ostream output (and istream input, see C++ Formatted Input) is the only overloading available for the GMP types and that
for instance using + with an mpz_t will have unpredictable
results. For classes with overloading, see C++ Class Interface.