Archived

This topic is now archived and is closed to further replies.

kuphryn

Reading and Writing Data From ifstream to *STL Container* in *Binary*

Recommended Posts

kuphryn    210
Hi. I am working on a simple program that reads data into memory in binary. It then write the data from memory to a second file in memory. Is it possible to read from ifstream straight to an STL container instead of having to go through dynamic memory allocation? Thanks, Kuphryn

Share this post


Link to post
Share on other sites
Kylotan    10011
Elaboration: it is possible in text mode, but not in binary. To read stuff in a string/int/whatever at a time, you can use an istream_iterator.

You possibly could do it for binary data, if you overloaded the >> operator for some sort of BinaryInput object it so that it used ''get()'' on the stream. But keeping it efficient and lightweight wouldn''t be easy.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Share this post


Link to post
Share on other sites