|
Boost Users : |
Subject: Re: [Boost-users] [BGL][Serialization] Reading a graph from a binary file: "vector subscript out of range error" and portability
From: Nicholas Mario Wardhana (mario.wardhana_at_[hidden])
Date: 2013-02-06 01:17:04
On 6 February 2013 00:13, Robert Ramey <ramey_at_[hidden]> wrote:
> Nicholas Mario Wardhana wrote:
>> int main()
>>
>> //std::ofstream filename1("binary_serialization.txt"); // error - open
>> in binary mode
> std::ofstream filename1("binary_serialization.txt", std::ios::binary);
>> boost::archive::binary_oarchive binary_oa(filename1);
>> binary_oa & g;
>> filename1.close();
>> }
>
Thank you very much Robert! As the resulting file looked "binary"
enough to me, I didn't realise that I missed the std::ios::binary flag
when saving the file. Your code solved the problem.
As for the portability, I found that there are a few affecting
factors, e.g. different variable sizes and processor architectures
[1]. However, I just generated the files on an another computer with
similar system, and the files are exactly the same as what I
previously generated on my computer. The other computer can read the
file properly. As I don't target too different architectures, I think
I am going to check myself to what extend the binary format is
portable.
Best regards,
Nicholas Mario Wardhana
References:
[1] http://www.eskimo.com/~scs/cclass/int/sx3b.html
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net