Help with reading and writing to a file

Steve Torri storri at torri.org
Fri Jun 11 19:09:23 CEST 2004


On Fri, Jun 11, 2004 at 06:55:57PM +0200, Michel Bardiaux wrote:
> On Unix:
> Command: od -bc mpz_test.dat
> Output:
> 0000000 001 000 000 000 350 003 000 000 001 000 000 000 065 060 060 060
>         001  \0  \0  \0 350 003  \0  \0 001  \0  \0  \0   5   0   0   0
> 0000020 071 060 060 060 001 000 000 000
>           9   0   0   0 001  \0  \0  \0
> 0000030
> 
> On Windows I dont know if one can save the window of a GUIed hexdump 
> utility as text.
> 
> And, yes, I gave a bad line. << "" *cant* work because it actually does 
> nothing! Sorry. Try
> 
> m_file_handle << val << "\n" (or << std:endl, should be equivalent)
> 
> What does the dump look like now? Is there a non-digit byte between the 
> strings 5000 and 9000 ?
> 
> You asked why the extra <<"\n" is not part of the << operator. Well, 
> that was standard C output and became standard C++ output:
> 
> stream << "12" << "34" produces 1234 and so does
> stream << "12" ; stream << "34"

Well the behaviour is not what I expect when I use the operator>> to
read. It should be documented better to say to the user that they are
required to send it. Or it can be added to the the operator<< for
writing values.

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

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.

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


More information about the gmp-discuss mailing list