When I assign a number for a section of an array it works.I know this because I output the data and it outputs what I have in my input.txt file.However, when I output it outside the while loop the first the number is the last number in my notepad file.
What do you mean when you say I am accessing my array out of bounds?
You have an array of size 1, so the only valid index value would be 0, anything else would be trying to access your array out of bounds, which you were doing on lines 39 and 40.
How do I go about fixing it?
I recommend you use a std::vector instead of the array and then push_back() the values into your vector. And then when you want to display the vector contents use the size() of the vector to limit your loop.
Edit: i thought you need it to be ifstream to read and write in it.
An ifstream is in input stream, always. An ofstream is an output stream, always. A fstream can be used for both input and output when used properly. Since you're only reading from your file all you need is to use an ifstream with the default open modes. std::ifstream myfile("input.txt");