C++ 为什么队列在中间元素处停止遍历?

C++ 为什么队列在中间元素处停止遍历?,c++,iterator,queue,C++,Iterator,Queue,当我尝试检查后缀表达式的更正时,在队列中的元素中间执行的输出值被中断。IDE没有任何提示,但我的代码中肯定存在一些问题。为什么会这样 这是我的测试代码: int main(){ op['('] = 0; op['+'] = op['-'] = 1; op['*'] = op['/'] = 2; while(getline(cin,str),str != "0"){//save the nifix expression for(s

当我尝试检查后缀表达式的更正时,在队列中的元素中间执行的输出值被中断。IDE没有任何提示,但我的代码中肯定存在一些问题。为什么会这样

这是我的测试代码:

int main(){
    op['('] = 0;
    op['+'] = op['-'] = 1;
    op['*'] = op['/'] = 2;
    while(getline(cin,str),str != "0"){//save the nifix expression
        for(string::iterator it = str.begin();it != str.end();it++){//checking progress
            if(*it == ' ') str.erase(it);
        }
        while(!s.empty()) s.pop();
        Change();
        /*printf("%d.2f\n",Cal());*/
        node t;
        printf("%d\n",q.size());
        for(int i = 0;i<q.size() && !q.empty();i++){
            t = q.front();
            if(t.flag == true){
                printf("%.0f ",t.num);
            }else{
                printf("%c ",t.op);
            }
            printf("%d\n",q.size());
                q.pop();
        }
        printf("\n");
    }

    system("pause");
    return 0;
}
intmain(){
op['(']=0;
op['+']=op['-']=1;
op['*']=op['/']=2;
while(getline(cin,str),str!=“0”){//保存nifix表达式
对于(string::iterator it=str.begin();it!=str.end();it++){//检查进度
如果(*it='')str.erase(it);
}
而(!s.empty())s.pop();
改变();
/*printf(“%d.2f\n”,Cal())*/
节点t;
printf(“%d\n”,q.size());

对于(int i=0;i让我们从一个完整但简单的示例开始,使用相同的循环逻辑:

#包括
#包括
使用名称空间std;
int main()
{
//排队
队列q;
//放一些东西进去
对于(int count=1;count<6;count++)q.push(count);
//运行asker的逻辑
对于(int index=0;indexprintf(“%d\n”,q.size());
中,
q.size()
不是
%d
的合适类型。至少它需要是
%u
,并且可能需要是
%lu
%llu
。使用
cout更安全
Index: 0, Queue size: 5
Index: 1, Queue size: 4
Index: 2, Queue size: 3
index: 0, Queue size: 5
index: 1, Queue size: 4
index: 2, Queue size: 3
index: 3, Queue size: 2
index: 4, Queue size: 1