结构体定义的时候,变量进行初始化必须在函数里面进行

#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();

}

posted on 2011-05-28 17:54  xuq  阅读(310)  评论(0编辑  收藏  举报

导航