Error code:
struct STUD
{
int ID;
char name[20];
float score;
}stud;
STUD SS[10];
student.open("student.dat",ios::in|ios::binary);
if(!student)
{
cout<<"failed to open file"<<endl;
return 0;
}
int j=0;
student.read((char *)&stud,sizeof(stud));
while(!student.eof()){
SS[j].name=stud.name;//error
SS[j].ID=stud.ID;
SS[j].score=stud.score;
j++;
student.read((char *)&stud,sizeof(stud));
}
student.close();
The purpose of this code is to read the data from the file. DAT and store it in the structure array object SS [J]. However, the assignment of SS [J]. Name is an error, which can be changed to strcpy (SS [J]. Name, student. Name). Here, if you use the equal sign, you need to overload the operator =. Pay attention to add the header file # include <cstring>
Similar Posts:
- C++ error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m…
- MySQL error message: subquery returns more than 1 row and its solution
- C++ Error: Run-Time Check Failure #2 – Stack around the variable ‘cc’ was corrupted.
- [design and development] Python learning notes – Super () argument 1 must be type, not classobj
- [Solved] Operator overload must take either zero or one argument error
- C write and read file via FILE and open method in a+ or r mode
- [Solved] Pycharm Error: TypeError: init() missing 1 required positional argument: ‘on_delete’
- How to Solve Const variable assignment Error
- QT Compilation error: invalid application of ‘sizeof’ to incomplete type ‘Qt3DRender::QPickEvent’
- [Solved] Protobuf Error: ‘tr1/unordered_map’ file not found