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.
First you have an array that has room for one and only one element, so what is the point of the array?
Second you file contains numbers, why are you using a string instead of a numeric type?
Third you're accessing your array out of bounds which leads to undefined behavior.
Fourth why are you opening the file in binary mode? You're using formatted input methods so you should be opening the file as a "text" file not binary.
And why are you trying force an ifstream to be an output stream (an ifstream is always an input stream)?
I added size to my array. What do you mean when you say I am accessing my array out of bounds? How is the 7 going through if it is out of bounds? How do I go about fixing it?
Edit: i thought you need it to be ifstream to read and write in it.
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");