第75行的cin有什么用,为什么删掉之后,运行输入空格的话无法出结果
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
#include<iostream>
using namespace std;
typedef char SElemType;
typedef struct{
SElemType *base;//栈顶指针
SElemType *top;//栈底指针
int stacksize;//栈可用最大容量
}SqStack;
int InitStack(SqStack &S){
S.base=new SElemType[MAXSIZE];//为栈分配一个容量为MAXSIZE的数组空间
if(!S.base)
exit(-1);//如果分配失败,退出
S.top=S.base;//空栈
S.stacksize=MAXSIZE;//设置栈的最大容量
return 1;
}
SElemType GetTop(SqStack S)
{
if(S.top!=S.base)
return *(S.top-1);
}
int StackEmpty(SqStack S){
if(S.top==S.base)
return 1;
else
return 0;
}
int Push(SqStack &S,SElemType e)
{
if(S.top-S.base==S.stacksize)//判断栈是否满
return 0;
*S.top++=e;//将元素放入栈顶
return 1;
}
int Pop(SqStack &S,SElemType &e)
{
if(S.top==S.base)
return 0;
e=*--S.top;
return 1;
}
int main()
{
char ch,x;
SqStack S;
InitStack(S);
int flag=1;
cout<<"在表达式结尾输入#来结束表达式:"<<endl;
cin>>ch;
while(ch!='#'&&flag)//以#来结束表达式
{
switch(ch)
{
case '[':
case '(':
Push(S,ch);
break;
case ')':
if(!StackEmpty(S)&&GetTop(S)=='(')
Pop(S,x);
else
flag=0;
break;
case ']':
if(!StackEmpty(S)&&GetTop(S)=='[')
Pop(S,x);
else
flag=0;
break;
}
cin>>ch;
}
if(StackEmpty(S)&&flag)
printf("匹配成功");
else
printf("匹配失败");
}
如果不想要75行的cin,想要删掉他,应该如何修改才能不影响正常运行