Surely you mean x to be an int, not a char? Where do you change the value of x to read a different member of the array? If you only use the first member of the array, why did you make the array with a size of 5? This is all very confused code.
while (i<5)
{ifstream infile;
char testinfo [10001];
infile.open("testinfo.txt");
cin.get (testinfo,10001);
cout<<testinfo<<endl;
//code omitted for brevity
}
I've only glanced at your code but I think the issue lies within yourwhileloop.
If you look at line 2 of the while loop (in this reply) you have declared the variable ifstream infileinside the while loop. This means everytime you iterate through, you are creating and accessing a new instance ofinfile.
istream::get(...) extracts data from the stream (ifstream infile), so when the while loop iterates it extracts the next lot of data from the stream. This however is not possible if you are constantly creating a new stream (this is a corollary of having the variable declarationinside thewhileloop).
You need to declare ifstream infile and open the fileoutside of the while loop.
Additionally I've noticed some peculiarities in your code:
On line 23: {cout<<"This is a test program"<<endl;}, why is this cout statement inside parentheses? You can remove them as they only serve to make your code illegible.
On line 26: while (i<5), I assume 5 relates to the number of lines in your input file. This may work now, however a better solution might be to use ifstream::good() (see: http://www.cplusplus.com/reference/iostream/ios/good/). These sorts of magic numbers are bad because should the format of your input file change, you will need to update your code, by using ifstream::good() you eliminate this problem..