Home > Back-end >  Hello I why this code will appear problem, but if the structure of the variable from a string into a
Hello I why this code will appear problem, but if the structure of the variable from a string into a

Time:01-20

#include
# 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 Filenode;
};
Vector The userlist;
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:

reference 1/f, mango black response:
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, suggested that the post code use code block insert
but I am in the for loop variables is called directly, not to create temp before ah, seems to be copied so typesetting sorry [face] monkey2:006 PNG [/face]