Jump to content
  • Advertisement

Archived

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

kuphryn

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

This topic is 6128 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
If the container is a vector or deque you could...

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

"What I see is a system that _could do anything - but currently does nothing !" - Anonymous CEO

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!