用户输入惊叹号后停止接受字符

时间:2015-07-12 07:43:53

标签: c++ stack

print list(sub_findre(s,substring,2))
[0, 1, 4, 8, 9, 10, 11, 15, 20, 23, 27, 28, 32, 33, 34, 39, 42, 46, 47, 48, 53, 56, 60, 61, 62, 67]

我在做Stacks数据结构。我写了什么代码,以便在用户输入惊叹号后停止接受字符?

1 个答案:

答案 0 :(得分:0)

输入感叹号时,只需从循环中断。

void main()
{
    Stack *S = new Stack;
    char val;

    while(true)
    {
        cout<<"enter character:"<<endl;
        cin>>val;
        if (val == '!') { // exclamation point was entered
             break;
        }
        S->push(val);
    }

    S->pop();
}