初学者问题,望高手指教!
#include "stdafx.h"#include "iostream.h"
class student
{
friend ostream & operator<<(ostream &,const student & );
friend istream & operator>>(istream & ,student & );
public:
student(student &);
student(int,string,string);
int getAge();
string getName();
string getClassName();
void setAge(int);
void setName(string);
void setClassName(string);
virtual ~student();
private:
int age;
string name;
string className;
};
student::student(student &stu)
{
this->age = stu.age;
this->className = stu.className;
this->name = stu.name;
}
student::student(int age,string name,string className)
{
this->age = age;
this->name = name;
this->className = className;
}
int student::getAge(){
return this->age;
}
string student::getName(){
return this->name;
}
string student::getClassName(){
return this->className;
}
void student::setAge(int age){
this->age = age;
}
void student::setName(string name){
this->name = name;
}
void student::setClassName(string className){
this->className = className;
}
student::~student()
{
}
int main(int argc, char* argv[])
{
return 0;
}
ostream & operator<<(ostream &out ,const student &stu){
out<<"this student info is :\n"
<<"name :"<<stu.name<<"\n"
<<"age :"<<stu.age<<"\n"
<<"className :"<<stu.className<<"\n"<<endl;
}
istream &operator>>(istream &in ,student &stu){
in>>"Please input this student info :\n"
cout<<"name is :"<<"\n";
in>>stu.name;
cout<<"age is:"<<"\n"
in>>stu.age;
cout<<"className is:"<<"\n";
in>>stu.className;
}
这是我的代码,为什么会报错误?
错误为:
stduentT.cpp
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(14) : error C2629: unexpected 'class student ('
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(14) : error C2238: unexpected token(s) preceding ';'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(16) : error C2146: syntax error : missing ';' before identifier 'getName'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(16) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(17) : error C2146: syntax error : missing ';' before identifier 'getClassName'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(17) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(19) : error C2061: syntax error : identifier 'string'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(20) : error C2061: syntax error : identifier 'string'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(24) : error C2146: syntax error : missing ';' before identifier 'name'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(24) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(24) : error C2501: 'name' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(25) : error C2146: syntax error : missing ';' before identifier 'className'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(25) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(25) : error C2501: 'className' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(31) : error C2039: 'className' : is not a member of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(31) : error C2039: 'className' : is not a member of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(32) : error C2039: 'name' : is not a member of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(32) : error C2039: 'name' : is not a member of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(35) : error C2061: syntax error : identifier 'string'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(36) : error C2511: 'student::student' : overloaded member function 'void (int)' not found in 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(9) : see declaration of 'student'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(46) : error C2143: syntax error : missing ';' before 'tag::id'
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(46) : error C2501: 'string' : missing storage-class or type specifiers
H:\Program Files\Microsoft Visual Studio\MyProjects\stduentT\stduentT.cpp(46) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
刚开始学习,就出这样的错误很郁闷,希望大家能帮帮小弟,谢谢!
[[it] 本帖最后由 fly_woniu 于 2008-5-3 18:35 编辑 [/it]]