Boost serialization: Problem reading strings from binary archive

Hello,
I am having a strange problem with std::string as I am trying to read
from a binary archive using Boost serialization. I am new to this, and
it is possible that I have not understood the usage. In the code
below, the string "faultblock" seems to be causing the problem. The
code crashes in the ia & tst line which is reading back the archive -
the stack indicates that it is trying to read an invalid string.
I have tried to minimize the code I need to post, but sorry if this is
still too much.
I'd appreciate any help with this. I am using Boost 1.34.0 on windows
XP.
Best Regards
Mahesh
//
// test.cpp
//
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include

try replacing
std::ofstream ofs("test.bin");
with
std::ofstream ofs("test.bin", ios::binary);
does that help?
Robert Ramey
"Mahesh Venkitachalam"

Yes, that was it - thanks very much for looking at it. I was using a text
archive before, and everything was working even after I switched to binary,
till I started using strings. I missed out on adding ios::binary to the
write...
Best Regards
Mahesh
On Nov 10, 2007 10:03 PM, Robert Ramey
try replacing std::ofstream ofs("test.bin"); with std::ofstream ofs("test.bin", ios::binary); does that help?
Robert Ramey
"Mahesh Venkitachalam"
wrote in message news:6164abb70711100543x284a2592p2189dd14a54d0d54@mail.gmail.com... Hello, I am having a strange problem with std::string as I am trying to read from a binary archive using Boost serialization. I am new to this, and it is possible that I have not understood the usage. In the code below, the string "faultblock" seems to be causing the problem. The code crashes in the ia & tst line which is reading back the archive - the stack indicates that it is trying to read an invalid string.
...
participants (2)
-
Mahesh Venkitachalam
-
Robert Ramey