I'm working on a small project that basically works like this: the user inputs a text file (via command line). The text file is a list of space separated numbers. I want to read over that list and put the numbers in an array (or an array). I'm just confused about how to create that array. My understanding of reading text files in pretty shaky.
1 2 3 4 5 6
I guess the logic behind the initial code would be something like:
while there are still numbers to read;
add to back of array
but how do I read over each number in the text file?
You don't even need to know the size, you can just let the size determine itself.
For each row, read in the entire line to a string and do input with a std::istringstream to extract each individual element. When there's no more data move on to the next row. When there's no more rows, you're done.