Help with reading and writing to a file

Michel Bardiaux mbardiaux at peaktime.be
Mon Jun 14 11:51:49 CEST 2004


Steve Torri wrote:

> 
> 
> Well the behaviour is not what I expect when I use the operator>> to
> read. 

It's absolutely standard C++ behaviour; so you *should* expect it.

> It should be documented better to say to the user that they are
> required to send it. 

Every C++ textbook documents it that way (or are you using Schildt?)

> Or it can be added to the the operator<< for
> writing values.

You can overload the operators yourself, of course, but personnally I 
would never change the behavior of a standard operator. It would be akin 
to overloading "<" so that it returns "less than or equal to".

> 
> The test program I have ran as follows when I added the std::endl to
> the writing of the mpf_class variables:
> 
> Wrote number: 5000.59584999999970023
> Wrote number: 609058.490409399964847
> in val: 6000
> Read number: 5000.59584999999970023
> Read number: 609058.490409399964847
> out val: 1536010

Sorry, could you repost the test program in its latest state?

> 
> The program writes and reads the values correctly for the mpf_class
> types. Yet the position of the get pointer for the ifstream is either
> incorrectly positioned when it attempts to start reading the uint32_t
> that was written after the 2 mpf_class types.

What's the value of the get pointer?

> 
> Here is the binary dump of the dat file:
> 
> storri at base storri $ od -bc boo
> 0000000 065 060 060 060 056 065 071 065 070 064 071 071 071 071 071
> 071
>           5   0   0   0   .   5   9   5   8   4   9   9   9   9   9
>           9
> 0000020 071 067 060 060 062 063 012 066 060 071 060 065 070 056 064
> 071
>           9   7   0   0   2   3  \n   6   0   9   0   5   8   .   4
>           9
> 0000040 060 064 060 071 063 071 071 071 066 064 070 064 067 012 160
> 027
>           0   4   0   9   3   9   9   9   6   4   8   4   7  \n   p
>           027
> 0000060 000 000
>          \0  \0
> 0000062
> 
> Stephen


-- 
Michel Bardiaux
Peaktime Belgium S.A.  Bd. du Souverain, 191  B-1160 Bruxelles
Tel : +32 2 790.29.41



More information about the gmp-discuss mailing list