manpagez: man pages & more
info gmp
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.3 C++ Formatted Input

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

Function: istream& operator>> (istream& stream, mpz_t rop)

Read rop from stream, using its ios formatting settings.

Function: istream& operator>> (istream& stream, mpq_t rop)

An integer like ‘123’ will be read, or a fraction like ‘5/9’. No whitespace is allowed around the ‘/’. If the fraction is not in canonical form then mpq_canonicalize must be called (see section Rational Number Functions) before operating on it.

As per integer input, an ‘0’ or ‘0x’ base indicator is read when none of ios::dec, ios::oct or ios::hex are set. This is done separately for numerator and denominator, so that for instance ‘0x10/11’ is 16/11 and ‘0x10/0x11’ is 16/17.

Function: istream& operator>> (istream& stream, mpf_t rop)

Read rop from stream, using its ios formatting settings.

Hex or octal floats are not supported, but might be in the future, or perhaps it’s best to accept only what the standard float operator>> does.

Note that digit grouping specified by the istream locale is currently not accepted. Perhaps this will change 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 section C++ Formatted Output) 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.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on March 31, 2014 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.