结构体定义的时候,变量进行初始化必须在函数里面进行
#include<iostream.h>
#include<stdio.h>
typedefstruct st{
char str[100];
int sp;
st(int i=-1){sp=i;}//直接赋值的方法是错误的
};
intmain()
{
charc;
stStack;
cout<<Stack.sp<<endl;
while((c=getchar())!='\n')
{
Stack.sp++;
Stack.str[Stack.sp]=c;
}
for(inti=Stack.sp;i>=0;i--)
cout<<Stack.str[i];
getchar();
}