Duncan wrote:[color=blue]
>
> I need to populate a vector with the following struct details:\
>
> struct group
> {
> string groupname;
> int gid;
> list<string> members;
> };
>
> the text file which this is to read from is in the following form:
>
> root 0 root,sarah,pdg,cdf,david,sah,simon,victor,yuan,dfs ,markus,andy
>
> the first bit is the groupname
> the number the gid
> and the names after that are the members in the STL list.
>
> I have so far defined the vector:
>
> vector<group*> vgroup;
>
> however i cannot work out how to populate the vector from the
> structure.
> I have never worked with structures and vectors together before but I
> know them seperatly very well.[/color]
Make it simpler.
Suppose there is just 1 struct group object
Also assume you have read just one line of input from the file
Are you able to populate that group object with the data read
in that single line?
group TheGroup
string TheLine;
getline( InFile, TheLine );
// Do you know how to work with TheLine to extract the
// information and fill in that information into TheGroup ?
If yes, the rest is easy.
Just define
vector< group > vgroup;
and do
vgroup.push_back( TheGroup );
and a copy of the TheGroup object will be appended in the vector.
You then can reuse the TheGroup object to process the next line
from the input, etc.
--
Karl Heinz Buchegger
kbuchegg@gascad.at