Saving the Number of the Elements in the File

Give up? Okay, here it is: when we create the file that contains the data for the HomeItem objects, we can start by writing the number of HomeItem objects as the first line of the file. This is the solution we used to preallocate the m_Track Vec that holds the track names for a “Music” HomeItem. The disadvantage of this solution is that it is harder to apply when the input file is generated directly by a human being, who is likely to make a mistake in counting the elements. However, this is not much of a drawback when we consider that the most common way to generate such a file in the real world is to create, edit, and delete items via a program. This program will read any pre-existing data file, ...

Get C++: A Dialog Programming with the C++ Standard Library now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.