after building this code, I've got an error message like this:
"Exception thrown at 0x00D8B410 in Prac2.exe: 0xC0000005: Access violation writing location 0xDDDDDDDD."
It seems to have a bug in this code but I can't find it out.
If you find it out, I will appreciate it very much.
Pay attention to what your compiler tells you. When it warns you about things, you should read them.
while (fscanf(fp, "%s %s", &u1.id, &u1.pwd)==1)
This is an attempt to write into two char arrays. However, u1.id is not a char array and u1.pwd is not a char array.
This code is a horrible mish-mash of C and C++. Don't do that. Unless you've got a really good reason, just go with C++.
So no fopen. No FILE*. Use a C++ input file stream.
Line 41 ofile.write((char*)&u, sizeof(user)); is not valid since user contains members of type std::string. std::string will point to data held on the heap, writing such pointers to a file will not store the actual text content.