|
-
January 25th, 2016, 04:22 AM
#5
Re: How to use C++ Boots installation and map serialization?
Code:
dataFile.write(reinterpret_cast<char *>(&ac), sizeof(ac));
This will only work if all the data is stored as part of the class (eg int, float etc). Where a dynamic type is used (eg string) this doesn't work as the data is stored in memory outside of the class. The class only holds a pointer to the data.
Code:
Account ac;
dataFile.seekg(0,ios::end);
int size = dataFile.tellg();
int totAc = size/sizeof(ac);
dataFile.seekg(0,ios::beg);
This code won't do what is expected if Account is written to the file properly because the size of name etc (a string) is variable - so the size of the data written for each Account record could be different.
For stream insertion/extraction for a user defined struct/class you need to override the operator<< (and operator>>) for the required class.struct. Is this part of the code you haven't included?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|