471,078 Members | 831 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,078 software developers and data experts.

valarray<bool>

How to save a valarray<bool> object in a file and how to read it back into a
valarray<bool> object? Thanks!
Jul 22 '05 #1
1 1432
On Fri, 02 Jul 2004 05:28:37 GMT, Busin <bu****@fidrep.com> wrote:
How to save a valarray<bool> object in a file and how to read it back
into a
valarray<bool> object? Thanks!


It depends, first of all you have to decide what format you want to save
the information in. Do you want compactness, human readablity, or what
exactly?

There no way for me to answer that for you so I'll make some assumptions.
Suppose we save all the false values as the character '0' and all the true
values as the character '1'. Now it would be easy just to write out a
sequence of zeros and ones, but this would lead to a problem when you came
to read the valarray back in, namely how would you tell how big the
valarray was? So probably (but again its your choice) its best to first
write out the size of the valarray and then a space and then a series of
zeros and ones, and maybe a newline at the end just to make it more human
readable (but again this is your choice).

E.g.

valarray size 5, constisting of false, true, true, false, false would end
up being written out as

5 01100

Does this give you something to work with? Ask again if you don't know how
to code this, but have a go yourself first. If you were hoping for a 'one
line' answer then your out of luck, you are going to have to do some work
yourself.

BTW why are you using a valarray<bool> anyway? Is there a good reason to
prefer it over vector<bool>?

john
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.