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

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

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

    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

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You could probably do something like that. Loop through your file and read each record into a temporary structure and then copy this structure into the container.

    However, it's often easier and more efficient to store pointers to the objects in the containers. In which case you'd need to allocate memory dynamically, as a copy of the pointer would be entered into the container rather than a copy of the object itself.
    zen

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay.

    Thanks.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading in 16 and 24-bit audio data into (32-bit) integer buffers
    By theblindwatchma in forum C Programming
    Replies: 2
    Last Post: 04-13-2008, 11:12 PM
  2. accessing my com port, writing and reading data
    By shoobsie in forum C Programming
    Replies: 7
    Last Post: 09-16-2005, 03:29 PM
  3. Help with Reading and writing binary data
    By Yasir_Malik in forum C Programming
    Replies: 3
    Last Post: 12-12-2004, 09:24 AM
  4. reading and writing data
    By chrismiceli in forum C Programming
    Replies: 1
    Last Post: 09-14-2003, 11:48 AM
  5. reading and writing to a data file
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 06-17-2002, 10:30 PM