Next time, make sure your tabs are right.
Here's your problem:
for (int f = 0; f < 302; f++)
{
iter++;
if (fileout[iter] == 0x74 && fileout[iter+1] == 0x68 && fileout[iter+2] == 0x65)
{
Firstly, what is the goal of iter++, while you already have f?
Now, your actual error: When f equal 301, iter will contain the same value. You can figure out yourself what the answer of 301 + 2 is.