请帮忙看一下有什么错误!

faithstone 2008-04-06 06:16:51
//————————————————————————————————————————
//student.h
class Student
{
public:
void set();
void display();
private:
int num;
string name;
int age;
int score;
};
//————————————————————————————————————————
//————————————————————————————————————————
//student.cpp
#include<iostream.h>
#include<string.h>
#include"student.h"
//using namespace std;


void Student::set()//不要搞错基本格式!!!
{
cin>>num;
cin>>name;
cin>>age;
cin>>score;
}


void Student::display()//不要搞错基本格式!!!
{
cout<<endl<<"学号:"<<num<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"分数:"<<score<<endl<<endl;
}
//————————————————————————————————————————
//————————————————————————————————————————
//main.cpp
#include<iostream.h>
#include<string.h>
#include"student.h"
int main()
{
char cChar;
cin>>cChar;
int iCount=0;
Student Stud[2000];
while(iCount>=0)
{
iCount++;
if(cChar!='*')
{
cout<<endl;
cout<<"请输入信息:";
Stud[iCount].set();
cout<<endl;
}
else
{
cout<<endl<<"停止输入,请退出!"<<endl<<endl;
exit(0);
}
Stud[iCount].display();
cin>>cChar;
}
return 0;
}
//————————————————————————————————————————
...全文
58 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2008-04-06
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 Inhibitory 的回复:]
#include <iostream.h>
#include <string.h>
#include"student.h"
//using namespace std;

使用string是包含头文件#include <string>, 而不是#include <string.h>
string.h是字符函数如,islower, isupper等字符函数的头文件,与string没有任何关系,呵呵.
[/Quote]
多谢提示!
「已注销」 2008-04-06
  • 打赏
  • 举报
回复
//————————————————————————————————————————
//student.h
class Student
{
public:
void set();
void display();
private:
int num;
char name[];
int age;
int score;
};
//————————————————————————————————————————
//————————————————————————————————————————
//student.cpp
#include <iostream.h>
#include <string.h>
#include"student.h"
//using namespace std;


void Student::set()
{
cin>>num;
cin>>name;
cin>>age;
cin>>score;
}


void Student::display()//不要搞错基本格式!!!
{
cout < <endl < <"学号:" < <num < <endl;
cout < <"姓名:" < <name < <endl;
cout < <"年龄:" < <age < <endl;
cout < <"分数:" < <score < <endl < <endl;
}
//————————————————————————————————————————
//————————————————————————————————————————
//main.cpp
#include <iostream.h>
#include <string.h>
#include"student.h"
int main()
{
char cChar;
cin>>cChar;
int iCount=0;
Student Stud[2000];
while(iCount>=0)
{
iCount++;
if(cChar!='*')
{
cout < <endl;
cout < <"请输入信息:";
Stud[iCount].set();
cout < <endl;
}
else
{
cout < <endl < <"停止输入,请退出!" < <endl < <endl;
exit(0);
}
Stud[iCount].display();
cin>>cChar;
}
return 0;
}
//————————————————————————————————————————
搞定!
「已注销」 2008-04-06
  • 打赏
  • 举报
回复
//————————————————————————————————————————
//student.h
class Student
{
public:
void set();
void display();
private:
int num;
char name[];
int age;
int score;
};
//————————————————————————————————————————
//————————————————————————————————————————
//student.cpp
#include <iostream.h>
#include <string.h>
#include"student.h"
//using namespace std;


void Student::set()
{
cin>>num;
cin>>name;
cin>>age;
cin>>score;
}


void Student::display()//不要搞错基本格式!!!
{
cout < <endl < <"学号:" < <num < <endl;
cout < <"姓名:" < <name < <endl;
cout < <"年龄:" < <age < <endl;
cout < <"分数:" < <score < <endl < <endl;
}
//————————————————————————————————————————
//————————————————————————————————————————
//main.cpp
#include <iostream.h>
#include <string.h>
#include"student.h"
int main()
{
char cChar;
cin>>cChar;
int iCount=0;
Student Stud[2000];
while(iCount>=0)
{
iCount++;
if(cChar!='*')
{
cout < <endl;
cout < <"请输入信息:";
Stud[iCount].set();
cout < <endl;
}
else
{
cout < <endl < <"停止输入,请退出!" < <endl < <endl;
exit(0);
}
Stud[iCount].display();
cin>>cChar;
}
return 0;
}
//————————————————————————————————————————
搞定!
Inhibitory 2008-04-06
  • 打赏
  • 举报
回复
#include <iostream.h>
#include <string.h>
#include"student.h"
//using namespace std;

使用string是包含头文件#include <string>, 而不是#include <string.h>
string.h是字符函数如,islower, isupper等字符函数的头文件,与string没有任何关系,呵呵.
「已注销」 2008-04-06
  • 打赏
  • 举报
回复
能不能运行试一下再说啊?兄弟!
arong1234 2008-04-06
  • 打赏
  • 举报
回复
用中文路径名是个很不好得习惯
arong1234 2008-04-06
  • 打赏
  • 举报
回复
你在头文件中用了string类型,但是没有告诉系统在哪找它定义。需要#include + using namespace
csdn5211 2008-04-06
  • 打赏
  • 举报
回复
#include <string.h>

另外在main.cpp里就不要了。
csdn5211 2008-04-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ttkk_2007 的回复:]
student.h里面,你要包含string头文件
#include <string>
[/Quote]
「已注销」 2008-04-06
  • 打赏
  • 举报
回复
还是不行啊!
ttkk_2007 2008-04-06
  • 打赏
  • 举报
回复
student.h里面,你要包含string头文件
#include <string>
「已注销」 2008-04-06
  • 打赏
  • 举报
回复
改了还是有错,再麻烦你帮忙看一下啦!
c:\documents and settings\帐号\桌面\c++程序设计\自写程序——新建工程(不可运行?)\student.h(10) : error C2146: syntax error : missing ';' before identifier 'name'
c:\documents and settings\帐号\桌面\c++程序设计\自写程序——新建工程(不可运行?)\student.h(10) : error C2501: 'string' : missing storage-class or type specifiers
c:\documents and settings\帐号\桌面\c++程序设计\自写程序——新建工程(不可运行?)\student.h(10) : error C2501: 'name' : missing storage-class or type specifiers
执行 cl.exe 时出错.

工程.obj - 1 error(s), 0 warning(s)
csdn5211 2008-04-06
  • 打赏
  • 举报
回复
exit(0);

应该是break;吧,exit把整个程序都给退了。

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧