I have a .dat file with numbers on each line. For example...
345
66478
43
60263
5212
8943346
...etc
I want to read in each line, one by one, and store each line into an index of an int array.
How would I do that? Also, would I first have to read through the file to see how many lines of numbers there are, and then set the array to that size?
I've been looking it up and it seems like there are so many ways to do this. Which one is the best for what I'm trying to do?
Well, the file will be automatically closed, in this case when the program ends. In general, when the fstream goes out of scope, the file is closed.
Personally I've always been in the habit of closing files when I'm done, (it's usually required in various other programming languages) but since C++ streams will do it for you, it's mostly not necessary, except perhaps in specific circumstances. An example might be when you want to output some data to a file, close it and then re-open it as an input file etc.