Hi need to copy the written objects in a file to copy to a array But following code gives me a Error
T Obj
T arr[20];
while(file.read((char*)&Obj,sizeof(Obj))){
int i=0;
i++
arr[i]==Obj;
}
Error C2678: binary ‘==’ : no operator found which takes a left-hand operand of type
Well, firstly, the operator
==is used for comparison, not assignment. For assignment, you want a single=. Secondly, your code is not portable, and possibly broken, because the way your object is stored on disk as a sequence of bytes is not necessarily the same way that it is stored in memory as aTobject. This is because different computers/platforms/compilers represent binary data in different ways. Plus, as Vlad mentions in the comment below, if instances ofTcontain internal pointers, (likestd::string), then your program will simply fall apart.You should probably look into a serialization library, or at least use C++ iostreams to serialize your object into a text format, then use an
istream_iteratorto read them from disk.