首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

大侠们来看看,该怎么解决

2012-03-05 
大侠们来看看#includeiostream.h structpeople{intsnochar*namechartel[11]floattallcharsex}void

大侠们来看看
#include   "iostream.h "
struct   people                        
            {
            int   sno;
            char   *name;
            char   tel[11];
            float   tall;  
    char   sex;
         
 
            };


   

   
   
void   main()
{  
  int   i=0;
  char   flag;

  people   *student[10];
 
  for(;i <=9;i++)
  {        
            cout < < "请输入学生姓名: " < <endl;

    cin> > student[i]-> name   ;

    cout < < "请输入学生的性别:m代表男性f代表女性,如果不是二者之一,则默认为男 " < <endl;

    cin> > student[i]-> sex;
   
    switch(student[i]-> sex)
    {case   'm ':   break;
      case   'f ':   break;
    default:   student[i]-> sex= 'm ';
    }

    cout < < "请输入此学生的联系电话: " < <endl;
           
    for(int   j=0;j <11;j++)
          {cin> > student[i]-> tel[j];
      if(student[i]-> tel[j]> '1 '||student[i]-> tel[j] < '0 ')
  {cout < < "请输入数字! " < <endl;
    j--;}
          }

    cout < < "请输入学生的身高 " < <endl;
    cin> > student[i]-> tall;
    cout < < "继续添加吗? " < <endl;
    cout < < "y   or   n(其它默认为n) ";
           
    cin> > flag;
    if(flag== 'y ')break;  
  }

}


才学结构体,不知道怎么回事,总是提示内存错误
那位大侠帮助下小弟

[解决办法]
people student[10];
student[i].name


而且你的结构体里name是个指针,还没申请空间你就cin肯定会有问题的

[解决办法]
for(;i <=9;i++)
{
student[i] = new people;
student[i]-> name = new char[10];
cout < < "请输入学生姓名: " < <endl;

热点排行