How do i get array to ignore an integer from a filee

So I have a file names sortme that reads:
5
d
99
0
3
45
2

I want to read this file to an array:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void readftoa(int x[], int &n)
{
   fstream input;
   input.open("sortme.txt")
   
   int i =0;
   input >> x[i];
   while (!input.eof())
   {
     i++;
     input >> x[i];
   }
   n=i;
   input.close();
}


In this file, 5 is the number of elements, d stands for descending, and the rest of the 5 numbers is what i want to put in my array. When i do this, it adds the number of elements, 5, to my array, I'm guessing because it's type int as well. How do i get it to not read that into the array?

1
2
3
4
5
6
7
8
9
std::ifstream input("sortme.txt"); //Open file in constructor
int num;
input >> num;
char sort_type;
input >> sort_type;
int i = 0;
while(input >> x[i]) //Do not use .eof()!
    ++i;
//No need to close file. It is done automatically 
Topic archived. No new replies allowed.