可能重复:
以正确的顺序输出队列
我有两个包含数字的队列,integerQueue 仅包含整数,realQueue 包含开头的 '.' 然后是以下数字。
如果只读入整数,我需要打印出整数队列,但如果 realqueue 中有数据,我需要打印出前半部分 integerqueu 然后后半部分 realqueu 以生成像 123.234 这样的实数
目前我的代码将打印实数 1。然后它将打印整数:2342343
我该如何解决这个问题,以便显示正确的输出?
//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 we 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' && !integerQueue.empty())
{
writeFile <<integerQueue.front()<<realQueue.front();
integerQueue.pop();
realQueue.pop();
}
}