输出实数或整数 我正在从文件中按字符读取一个数字字符。它将读取一个整数并将其推入integerQueue直到达到'。',然后它将切换到将其输入到realQueue中。
然后当我打印时,它需要打印出来,即Real:123.4343
但是现在输出是Real:123。整数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();
}
}
答案 0 :(得分:1)
尝试提交此循环,看看会发生什么。
while(!integerQueue.empty() && currentState == '2')
{
writeFile <<integerQueue.front();
integerQueue.pop();
}