# include
# include
# include
# include
using namespace std;
Struct file {
Int protect [2].//set the three security code - r - w - x
The string filename.
Int length;
The string content;
};
Struct User {
String ID;
Vector
};
Vector
Void initiate () {
Fstream infile.
Infile. Open (" data. TXT ");
int n;
The file temp2;
while (! Infile. Eof ()) {
The User temp;
Infile & gt;> Temp. ID;
Infile & gt;> n;
The userlist. Push_back (temp);
for (int i=0; I & lt; n; I++) {
Infile & gt;> Temp2. Protect [0];
Infile & gt;> Temp2. Protect [1].
Infile & gt;> Temp2. Protect [2];
Infile & gt;> Temp2. Filename;
Infile & gt;> Temp2. Length;
Infile & gt;> Temp2. The content;
Userlist [userlist. The size () - 1]. Filenode. Push_back (temp2);
}
}
Infile. Close ();
}
Int main ()
{
Initiate ();
Printf (" User list are bellow: ");
for (int i=0; I & lt; The userlist. The size (); I++) {
Cout & lt;
}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data. TXT -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Peter
1
1
1
1
Happy
5
Nihao
Mike
1
1
1
1
Angry
5
Lihai
Bird
1
1
1
1
Hello
4
haha
CodePudding user response:
The userlist. Push_back (temp);The userlist of is a copy of the temp
You put the for loop before the push_back, or stored in the userlist User * pointer type
And you want to die the typesetting, suggest to use code block inserted into the post code
CodePudding user response: