Reading number from txt file and putting them into an array

Hello,
I'm a C++ beginner and would like to know how to read numbers from a txt file and put those numbers into an array. There are several sets of numbers and they need to be put into different arrays. This is the format of the txt file:

25:
6 5 0 8 7 6 1 6 5 9 2 3 0 5 9 5 7 4 4 3 6 6 6 9 1

5:
4 9 5 4 5

Note: I don't know if it matters but a few of the sets have 500+ plus numbers. Also these numbers and will be used for sorting.

Is this a homework where you have to use arrays ?
Much better is to use vectors.
https://www.codeproject.com/Articles/20930/The-complete-guide-to-STL-Part-Vector
Hello mrbossjb,

Reading the file and putting the numbers into an array is the easy part.

What you need to figure out first is if you want a fixed size array, a dynamic array that you can create as you read the file or as Thomas1965 suggested and I would go along with is to use a vector. The vector will only hold what you need and nothing extra like a fixed array that would need to be bigger than what you might need.

As an example you say some sets may be over 500 numbers, so you create an array of 550, but only use the first five that leaves you 545 unused elements.

It would help to have a better idea of what you need to do to help you with your question.

Hope that helps,

Andy
Hi Andy,

What I’m doing is running several sorting functions such as Insertion Sort and Merge Sort. I have the code to run everything but as it stands now, I would have to input each number into the arrays individually. So I guess I could use vectors as you guys suggested. There are 6 sets of numbers and I listed the format of the txt file in my original post. The txt file has the amount of numbers followed by the actual numbers.
Topic archived. No new replies allowed.