Hi all, I'm currently trying to write a program which can read objects from a file into an array. Towards the end of the program I then want it to write out the contents of the array into the file. I have had some level of success with it so far, my reading from file method seems to work with no issues and to a degree I know I am close with my write to file method. It works, but it also outputs the array's new elements made by the default constructor. Is there any way I can prevent these default objects being written to file or better yet, made in the first place?
Here are my member variables default constructor and methods in my class
Instead of reading/writing a set amount of times, you could keep track of the number of items successfully read from the file and write the same amount back to it.
As for not creating them at all, consider using a std::vector rather than an array.
When writing back to the array with a amount of items variable, would it be possible to leave a blank space at the end of the array? or is that not possible with object arrays?