-1

处理输出实数或整数我正在从文件中逐个字符地读取数字。它将读取一个整数并将其推入 integerQueue 直到它到达一个“。”,然后它将切换到将其输入到一个 realQueue 中。

然后当我打印时,它需要打印出来,即 Real: 123.4343

但现在输出是 Real: 123. Integer 4343

不知何故,我的 while 循环或我的 if 语句没有完成它的工作。我只是找不到我的错误

问题是,如何修复我的输出以便打印出 123.4343

    //if the realQueue is empty, then we just read in an integer, currentState must be 1, in order to print integer
            if(realQueue.empty() || currentState == '1')//implementation of the FSM
            {
                    writeFile <<"Integer:       ";
                    while(!integerQueue.empty())
                    {
                    writeFile <<integerQueue.front();
                    integerQueue.pop();
                    }
            }
            //since the realQueue has values in it, then it must bea real Number
            else
            {
                //currentState = '2';
                // currentState must be == '2', since wwe have a real number to print

                    writeFile<<"Real:           ";
                        //currentState has to be in real mode for it to print out to file
                        while(!integerQueue.empty() && currentState == '2')
                        {
                        writeFile <<integerQueue.front();
                        integerQueue.pop();
                        }
                        // currentState has to be in real mode for it to print out to file
                        while(!realQueue.empty() && currentState == '2')
                        {
                        writeFile <<realQueue.front();
                        realQueue.pop();
                        }

            } 
4

1 回答 1

1

尝试退出这个循环,看看会发生什么。

while(!integerQueue.empty() && currentState == '2') 
{ 
  writeFile <<integerQueue.front(); 
  integerQueue.pop(); 
} 
于 2012-10-05T06:58:37.157 回答