I want to read data into an array from a data file. Because I do not know, ahead of time, how much data is contained within the file I need to declare the array at run time using new.
My current strategy is the read through the data file to find out how many data elements there are. Then I declare the array using the number of data elements I learned from the first read. Then I read through the data file a second time to place items into the array.
Is this the most efficient way to accomplish this task?
In general, it seems that reading and writing to the hard disk is the slowest thing that a program will do. So, if I could accomplish my task by reading through the file only once it would make the program faster.
The question is: how do I do that?