You could read the first line, create an array of size one, populate the first element.
Try to read the next line; if it doesn't exist, done.
If it does exist, create an array of size (size of the current array, plus one), copy everything from the current array into the new array, delete the current array, and then populate the newly created last element of the array. Now go back to "Try to read the next line..." above.
Alternatively, you could read all the lines first, counting how many there are. Make an array that size. Then read all the lines again, but this time each time you read a line, populate an element of the array.
I would but my professor doesn't want us to use vectors. :( |
I am so sick of teachers of C++ starting with the more advanced use of raw arrays and manual memory management. Teach beginners beginner level C++. it's so ******* obvious; what is
wrong with these people?