Re: vector <int> load from file

From: Jerry Coffin (jcoffin_at_taeus.com)
Date: 01/17/04


Date: Sat, 17 Jan 2004 04:26:45 GMT

In article <Aj0Ob.182701$AAe1.116555
@news01.bloor.is.net.cable.rogers.com>, pingstephen@coldmail.com says...
> I figured out how to put a vector of ints out into a file. Now I want to get
> them back into the program - how do I load a bunch of integers in a file
> back into the program into a vector? Thanks.

You start by storing _all_ the information about the vector you're
storing -- not just its contents, but its size as well. That way if
(for example) you create a stream of two vectors, you can reconstruct
both of them properly.

Once you've done that, reading in a vector is pretty trivial: first,
open the file and read the first file. Use it to set the size of the
vector, and save it. Then take the saved value and iterate through
reading that many values from the input file, and pushing them onto your
vector.

-- 
    Later,
    Jerry.
The universe is a figment of its own imagination.


Relevant Pages

  • Re: making a calulation from two files - getline version
    ... unnesesarily write a relatively lengthy procedural program in awk, ... your solution requires storing ALL of the first file. ... store what is not needed. ...
    (comp.lang.awk)
  • Re: Compare two .dat files
    ... The first file contains a student name and ... As far as reading them "at the same time", ... through the arrays, investigate the "Perform" verb. ...
    (comp.lang.cobol)
  • Re: Limit To List - table showing incorrect data
    ... After reading your message I was able to search through some posts ... unbound text box is not storing the correct value. ... On Nov 18, 12:26 pm, John W. Vinson ...
    (microsoft.public.access.formscoding)
  • Reading files
    ... would you go about reading the file and storing each field in a ... sdsds dsfsdf4r33 ... sdassa er353fds ...
    (comp.unix.shell)
  • Re: Reading files
    ... > would you go about reading the file and storing each field in a ... > sdassa er353fds ... Linux solution for data management and processing. ...
    (comp.unix.shell)