Steve Chow wrote:
rough example I have two structs
typedef struct
{
int yaxis;
int xaxis;
int length;
}Cords;
Why would you use a typedef like this in C++. Unlike C, where `struct's
have their own namespace, in C++ using the simple:
struct Cords {
int ...
...
};
creates a type called `Cords'.
typedef struct
{
int number;
char type;
Cords *cords;
Why are you not using a std::vector here? It's just the Right Way (tm)
to go.
}Province;
I have a file that looks like
1 //Should be read into Province.number
20 40 80 //Should be read into Province.Cords.yaxis xaxis and length
respectively
21 39 80
......
9 // 9 Terminates
2
50 80 20
......
9
So basically, I need a way of pouring an unknown amount of blocks that
terminate with 9 from a file, into an unknown amount of Province
structures, when it gets to the sole #9 it should move onto another
Province structure.. ideas? (or better ideas to indicate that it should
move onto another structure?)
examples please.
Well, if you insist upon trying to do it the `C' way, you'll have to
allocate space on the fly and use realloc() when you need more. A common
strategy is to double the number of potential entries whenever you run
out and do a final trim when you're done.
Using std::vector, however, is clearly the way to go.
==========
One more quick note: You should always show what you've tried; just
asking: "How do I do it?" is not nearly as likely to get you help, nor
is the help you get likely to be as valuable in the long run.
HTH,
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"