 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alex J. Dam Guest
|
Posted: Wed Jan 28, 2004 9:54 pm Post subject: Standard Library types |
|
|
Hi,
I'm reposting this since I posted it as an answer and the topic changed a
little (guess no one bothered looking at it).
If I need to store the location of some data within a binary file, in that
same binary file, should I store the pos_type value returned by
ostream::teelp()? (That would be strange. I would be storing extra
information, since I need only the position).
I'm confused as to what types should be used when calling Standard Library
functions, especially when mixing variables of different types, e.g., if I
divide an off_type by a size_t, what do I get?
Thanks.
--
Alex J. Dam
"Oh, I got plenty o' nuttin',
an' nuttin's plenty fo' me"
-- Porgy
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Wed Jan 28, 2004 11:04 pm Post subject: Re: Standard Library types |
|
|
"Alex J. Dam" <alexjdam (AT) yahoo (DOT) com.br> wrote...
| Quote: | If I need to store the location of some data within a binary file, in that
same binary file, should I store the pos_type value returned by
ostream::teelp()? (That would be strange. I would be storing extra
information, since I need only the position).
I'm confused as to what types should be used when calling Standard Library
functions, especially when mixing variables of different types, e.g., if I
divide an off_type by a size_t, what do I get?
|
I would say, you get off_type. If it's an arithmetic type, a value of
that type retains its type no matter how you slice it or dice it.
My solution was always simpler: since binary files are platform-specific
(in most cases, anyway), then store the position as a long or unsigned
long (or any other type that can accommodate the maximum size of the
file). Once you retrieve it, convert it to the necessary off_type or
pos_type or whatever.
V
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Thu Jan 29, 2004 3:27 am Post subject: Re: Standard Library types |
|
|
"Alex J. Dam" <alexjdam (AT) yahoo (DOT) com.br> wrote
| Quote: |
Hi,
I'm reposting this since I posted it as an answer and the topic
changed a
little (guess no one bothered looking at it).
If I need to store the location of some data within a binary file,
in that
same binary file, should I store the pos_type value returned by
ostream::teelp()? (That would be strange. I would be storing extra
information, since I need only the position).
I'm confused as to what types should be used when calling Standard
Library
functions, especially when mixing variables of different types,
e.g., if I
divide an off_type by a size_t, what do I get?
|
Be aware that a stream's pos_type is not an intergral type, although
it can be converted to one. In general, this conversion could loose
information, although this may be unlikely with a stream in binary
mode.
Jonathan
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|