Boost logo

Boost Users :

From: Bill Lear (rael_at_[hidden])
Date: 2007-04-17 22:51:14


On Tuesday, April 17, 2007 at 18:17:22 (-0800) Gennady Khokhorin writes:
>I have vector<double> timeStamps;
>How to store this vector to outside binary file in boost style?
>I'm trying to utilyze mapped file:
>
>std::vector<double> timeStamps;
>std::string filePath("c:\\double_test.bin");
>boost::intmax_t thisFileSize(maxSize); // max good value: 0x2FFFFFFF
>ios::filtering_ostream out;
>ios::file_sink fsink(filePath);
>out.push(fsink);
>//out.write(time_stamps.begin(), thisFileSize); //
>out.flush();
>fsink.close();

Use serialization, though not sure a mapped file is what you want:

template<typename Archive>
struct Serializer {
    static void save(const vector<double>& timeStamps) {
        std::ofstream ofs("file.bin", std::ios::binary);

        Archive oa(ofs);
        oa << timeStamps;
    }
};

Serializer<binary_oarchive>::save(timeStamps);

See the doc on serialization, read thoroughly, make it your friend.

Bill


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