Проблема с чтением из файла, вызывающих бесконечный цикл

Хорошо, эта программа, над которой я работаю, кажется, все в порядке, за исключением проблемы. Вот код

#include <iostream>
#include <fstream>

using namespace std;

/*
Function Name: CalculateBinary
CalculateBinary takes a number from the main function and finds its binary form.
*/

void CalculateBinary( long InputNum)
{   
    //Takes InputNum and divides it down to "1" or "0" so that it can be put in binary form.
    if ( InputNum != 1 && InputNum != 0)
        CalculateBinary(InputNum/2);

    // If the number has no remainder it outputs a "0". Otherwise it outputs a "1". 
    if (InputNum % 2 == 0)
        cout << "0";
    else
        cout << "1";
}


void main()
{
    // Where the current number will be stored
      long InputNum;

    //Opens the text file and inputs first number into InputNum. 
    ifstream fin("binin.txt");
    fin >> InputNum;

    // While Input number is not 0 the loop will continue to evaluate, getting a new number each time.
    while (InputNum >= 0)
    {
        if(InputNum > 1000000000)
            cout << "Number too large for this program ....";
        else
            CalculateBinary(InputNum);

        cout << endl;
        fin >> InputNum;        
    }
}

Вот текстовый файл, который я читаю в

12
8764
 2147483648
2
-1

, когда я добираюсь до 8764, он просто продолжает читать в этом номере снова и снова. Он игнорирует 2147483648. Я знаю, что могу решить это, объявляя Protuctnun в долгомлении. Но я хочу знать, почему это делает это?

0
задан Steffan Harris 13 September 2011 в 16:58
поделиться