c++11 - A valid solution to write objects containing strings into files? -


please can explain meaning of 2nd line of following code?

book *b; b=(book *)new char[sizeof(book)]; f1.read((char*)b,sizeof(book)); 

this 1 of suggestions found writing object of class book (which contains std::strings) file.
ps: works !!

the code included not "write objects." reads array of bytes f1.

that code not correct c++ either. can never byte copies of c++ object contains other objects, because might contain pointers or virtual function tables. copying them file worse because pointers point memory doesn't exist anymore. , fyi, std::string has pointer.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -