You chould exchange conditions in the while statement
while ( i < arr.size() && a != arr[i] ) i++;
Also this condition is wrong
while(!text.eof())
{
text>>a;
The eof state can occur after statement
text>>a;
in the block of the while.
Change it to
while ( text >> a )