| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1891 人关注过本帖
标题:C++一个程序出错了,求高手解答
只看楼主 加入收藏
tingting555
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2017-3-27
结帖率:0
收藏
已结贴  问题点数:10 回复次数:1 
C++一个程序出错了,求高手解答
#ifndef _STUDENT
#define _STUDENT
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 80
class Student
{
    string name;
    string ID;
    string number;
    string speciality;
    int age;
public:
    Student();
    Student(string na,string id,string num,string spec,int ag);
    Student(const Student &per);
    ~Student();
    string GetName();
    string GetID();
    string GetNumber();
    string GetSpec();
    int GetAge();
    void Display() const;
    void Input();
    bool Insert( );
};
#endif
#include"example7_19_Student.h"
Student::Student()
{
    age=0;
}
Student::Student(string na,string id,string num,string spec,int ag)
{
    name=na;
    ID=id;
    number=num;
    speciality=spec;
    age=ag;
}
Student::Student(const Student &per)
{
    name=per.name;
    ID=per.ID;
    number=per.number;
    speciality=per.speciality;
    age=per.age;
}
Student::~Student()
{}
    string Student::GetName()
    {
   return name;
    }
   string Student::GetID()
   {
       return ID;
   }
   int Student::GetAge()
   {
       return age;
   }
   string Student::GetSpec()
   {
       return speciality;
   }
   string Student::GetNumber()
   {
       return number;
   }
   void Student::Display() const
   {
       cout<<"姓名"<<name<<endl;
       cout<<"身份证"<<ID<<endl;
       cout<<"学号"<<number<<endl;
       cout<<"专业"<<speciality<<endl;
       cout<<"年纪"<<age<<endl<<endl;
   }
   void Student::Input()
   {
       cin.get();
       cout<<"输入姓名";
       getline(cin,name);
       cin.get();
       cout<<"输入身份证";
       getline(cin,ID);
       cin.get();
       cout<<"输入专业";
       getline(cin,speciality);
       cout<<"输入年龄";
       cin.get();
       cin>>age;
   }
#include<iostream>
#include<vector>
#include<algorithm>
#include"example7_19_Student.h"
using namespace std;
void menu();
void OutputStu(vector<Student>& stu_vec);
void InputStu(vector<Student>& stu_vec);
int main()
{
    vector<Student> stu_vec;
    int choice;
    string na;
    do
    {
        menu();
        cout<<"输入选择";
        cin>>choice;
        if(choice>=0 && choice<=3)
            switch(choice)
        {
    case 1:InputStu(stu_vec);
    break;
     case 2:cout<<"输入名字查找"<<endl;
       cin.get();
       getline(cin,na);
       cin.get();
       vector<Student>::iterator p;
       for(p=stu_vec.begin();p!=stu_vec.end();p++)
       {
             if(((*p).GetName()).compare(na)==0)
          {
              (*p).Display();
              break;
          }
      }
          if(p==stu_vec.end())
        cout<<"没有此人";
        break;
     case 3:OutputStu(stu_vec);break;
     default:break;
        }
    }while(choice);
return 0;
}
void menu()
{
   cout<<"1.录入信息"<<endl;
   cout<<"2.查询信息"<<endl;
   cout<<"3.浏览信息"<<endl;
   cout<<"0.退出"<<endl;
}
void OutputStu( vector<Student>& stu_vec)
{
    int count=0;
    vector<Student>::const_iterator p;
    for(p=stu_vec.begin();p!=stu_vec.end();p++)
    {
        (*p).Dispaly();
        cout++;
    }
    cout<<"学生总人数"<<count<<endl;
}
void InputStu( vector<Student>& stu_vec)
{
    char ch;
    Student x;
    do
    {
        x.Input();
        stu_vec.push_back(x);
        cout<<"继续输入?(Y/N)"<<endl;
        cin.get();
        cin.get(ch);
    }while(ch=='Y');
}
他出现的错误是40    11    C:\Users\77461\Desktop\新建文件夹\未命名3.cpp    [Error] jump to case label [-fpermissive]
28    31    C:\Users\77461\Desktop\新建文件夹\未命名3.cpp    [Error] crosses initialization of 'std::vector<Student>::iterator p'
42    3    C:\Users\77461\Desktop\新建文件夹\未命名3.cpp    [Error] jump to case label [-fpermissive]
28    31    C:\Users\77461\Desktop\新建文件夹\未命名3.cpp    [Error] crosses initialization of 'std::vector<Student>::iterator p'
60    8    C:\Users\77461\Desktop\新建文件夹\未命名3.cpp    [Error] 'const class Student' has no member named 'Dispaly'
61    7    C:\Users\77461\Desktop\新建文件夹\未命名3.cpp    [Error] no 'operator++(int)' declared for postfix '++' [-fpermissive]
搜索更多相关主题的帖子: public include number 
2017-06-18 16:45
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:10 
第一个错误,
case 2:
    ……
    vector<Student>::iterator p;
    ……
    break;
改为
case 2:
    {
    ……
    vector<Student>::iterator p;
    ……
    }
    break;

第二个错误
(*p).Dispaly(); 估计你想写的是 (*p).Display();

第三个错误
cout++; 估计你想写的是 count++;
2017-06-19 08:14
快速回复:C++一个程序出错了,求高手解答
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016139 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved