Re: vector <int> load from file
From: Jerry Coffin (jcoffin_at_taeus.com)
Date: 01/17/04
- Next message: Jumbo: "Re: working with addresses"
- Previous message: Jerry Coffin: "Re: working with addresses"
- In reply to:(deleted message) Stephen: "vector <int> load from file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Jumbo: "Re: working with addresses"
- Previous message: Jerry Coffin: "Re: working with addresses"
- In reply to:(deleted message) Stephen: "vector <int> load from file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|