Node:C++ Formatted Input, Previous:Formatted Input Functions, Up:Formatted Input



C++ Formatted Input

The following functions are provided in libgmpxx, which is built only if C++ support is enabled (see Build Options). Prototypes are available from <gmp.h>.

istream& operator>> (istream& stream, mpz_t rop) Function
Read rop from stream, using its ios formatting settings.

istream& operator>> (istream& stream, mpq_t rop) Function
Read rop from stream, using its ios formatting settings.

An integer like 123 will be read, or a fraction like 5/9. If the fraction is not in canonical form then mpq_canonicalize must be called (see Rational Number Functions).

istream& operator>> (istream& stream, mpf_t rop) Function
Read rop from stream, using its ios formatting settings.

Hex or octal floats are not supported, but might be in the future.

These operators mean that GMP types can be read in the usual C++ way, for example,

mpz_t  z;
...
cin >> z;

But note that istream input (and ostream output, see C++ Formatted Output) is the only overloading available and using for instance + with an mpz_t will have unpredictable results.