input operators shouldn't clear eof

Oncaphillis oncaphillis at
Tue Dec 21 11:31:29 CET 2010


This may be more a feature request then a bug report, but the input operator
of gmpxx shouldn't clear the eof flag on the istream.

I very often so string=>number conversion via std::stringstream like in the
flollowing code:


#ifdef WITH_GMP
#include <gmpxx.h>
typedef mpz_class   Value_t;
typedef int64_t     Value_t;

Value_t FromString(const std::string & rVal)
     std::stringstream ss(rVal);
     Value_t v;

     if( ! (ss >> v) || !ss.eof() )
         std::cerr << " failed to parse '" << rVal << "' as a number " 
<< std::endl;
     return v;

Checking eof here tells me that the string has been completely parsed. 
It works fine
with standard types but fails on gmpxx. Checked it on 4.3.2 and 5.0.1

I attached a patch against 5.0.1


-------------- next part --------------
A non-text attachment was scrubbed...
Name: gmp.patch
Type: text/x-patch
Size: 1351 bytes
Desc: not available
URL: <>

More information about the gmp-bugs mailing list