且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从文件读取导致无限循环的问题

更新时间:2023-11-14 21:54:04

这是你写的循环的常见问题。

That is the usual problem with such loops which you've written.

正确的和惯用的循环是:

The correct and the idiomatic loop is this:

ifstream fin("binin.txt");
long InputNum;
while (fin >> InputNum && InputNum >= 0)
{
   //now construct the logic accordingly!
    if(InputNum > 1000000000)
         cout << "Number too large for this program ....";
    else
         CalculateBinary(InputNum);
    cout << endl;
}