\c++\c++实验\练习\123\Debug\123.exe : fatal error LNK1169: 找到一个或多个多重定义的符号 5
#include<iostream>#include<fstream>#include<string>usingnamespacestd;classPerson{publ...
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class Person
{public:
string xm,xb;
public:
Person(string a,string b){xm=a;xb=b;}
int prt(){cout<<"姓名:"<<xm<<' '<<"性别:"<<xb<<endl;return 0;}
friend ostream &operator<<(ostream &fout,Person &p)
{ fout<<"姓名:"<<p.xm;
fout<<"性别:"<<p.xb;
return fout;
}
};
class Student:public Person
{public:
string xh,zy;
double cj;
public:
Student(string P_a,string P_b,string c,string d,double e):Person(P_a,P_b),xh(c),zy(d),cj(e){}
int prt(){cout<<"姓名:"<<xm<<' '<<"性别:"<<xb<<' '<<"学号:"<<xh<<' '<<"专业:"<<zy<<' '<<"成绩:"<<cj<<endl;return 0;}
friend ostream &operator<<(ostream &fout,Student &p)
{ fout<<"姓名:"<<p.xm<<' '<<"性别:"<<p.xb<<' '<<"学号:"<<p.xh<<' '<<"专业:"<<p.zy<<' '<<"成绩:"<<p.cj<<endl;
return fout;
}
friend istream &operator>>(istream &fin,Student &p)
{fin>>p.xm>>p.xb>>p.xh>>p.zy>>p.cj;
return fin;
}
};
void main()
{
int i,j,k=0;
Student t("Tom","Male","20110001","通信",0);
Person b("Tom","Male");
Student a[10]={Student("Tom","Male","20110001","通信",0),Student("Jerry","Male","20110002","通信",0),\
Student("Helen","Female","20110003","通信",0),Student("Tom","Male","20110001","通信",0),Student("Tom","Male","20110001","通信",0),\
Student("Tom","Male","20110001","通信",0),Student("Tom","Male","20110001","通信",0),Student("Tom","Male","20110001","通信",0),\
Student("Tom","Male","20110001","通信",0),Student("Tom","Male","20110001","通信",0),};
ofstream f1("d:\\成绩单原件.txt");
cout<<"输入10个学生数据:"<<endl;
for(i=0;i<10;i++)
{cin>>a[i];
f1<<a[i];}
ofstream f2("d:\\成绩单排序.txt");
for(i=1;i<10;i++)
for(j=0;j<10-i;j++)if(a[j].cj<a[j+1].cj){t=a[j+1];a[j+1]=a[j];a[j]=t;}
cout<<"按成绩排序后:"<<endl;
for( i=0;i<10;i++){f2<<a[i]<<endl;cout<<a[i]<<endl;}
}
这个错误应该怎么改啊,如果用vc6.0可以运行,但是用2010调试能通过却不能运行,谁能帮帮忙啊,谢谢啦~ 展开
#include<fstream>
#include<string>
using namespace std;
class Person
{public:
string xm,xb;
public:
Person(string a,string b){xm=a;xb=b;}
int prt(){cout<<"姓名:"<<xm<<' '<<"性别:"<<xb<<endl;return 0;}
friend ostream &operator<<(ostream &fout,Person &p)
{ fout<<"姓名:"<<p.xm;
fout<<"性别:"<<p.xb;
return fout;
}
};
class Student:public Person
{public:
string xh,zy;
double cj;
public:
Student(string P_a,string P_b,string c,string d,double e):Person(P_a,P_b),xh(c),zy(d),cj(e){}
int prt(){cout<<"姓名:"<<xm<<' '<<"性别:"<<xb<<' '<<"学号:"<<xh<<' '<<"专业:"<<zy<<' '<<"成绩:"<<cj<<endl;return 0;}
friend ostream &operator<<(ostream &fout,Student &p)
{ fout<<"姓名:"<<p.xm<<' '<<"性别:"<<p.xb<<' '<<"学号:"<<p.xh<<' '<<"专业:"<<p.zy<<' '<<"成绩:"<<p.cj<<endl;
return fout;
}
friend istream &operator>>(istream &fin,Student &p)
{fin>>p.xm>>p.xb>>p.xh>>p.zy>>p.cj;
return fin;
}
};
void main()
{
int i,j,k=0;
Student t("Tom","Male","20110001","通信",0);
Person b("Tom","Male");
Student a[10]={Student("Tom","Male","20110001","通信",0),Student("Jerry","Male","20110002","通信",0),\
Student("Helen","Female","20110003","通信",0),Student("Tom","Male","20110001","通信",0),Student("Tom","Male","20110001","通信",0),\
Student("Tom","Male","20110001","通信",0),Student("Tom","Male","20110001","通信",0),Student("Tom","Male","20110001","通信",0),\
Student("Tom","Male","20110001","通信",0),Student("Tom","Male","20110001","通信",0),};
ofstream f1("d:\\成绩单原件.txt");
cout<<"输入10个学生数据:"<<endl;
for(i=0;i<10;i++)
{cin>>a[i];
f1<<a[i];}
ofstream f2("d:\\成绩单排序.txt");
for(i=1;i<10;i++)
for(j=0;j<10-i;j++)if(a[j].cj<a[j+1].cj){t=a[j+1];a[j+1]=a[j];a[j]=t;}
cout<<"按成绩排序后:"<<endl;
for( i=0;i<10;i++){f2<<a[i]<<endl;cout<<a[i]<<endl;}
}
这个错误应该怎么改啊,如果用vc6.0可以运行,但是用2010调试能通过却不能运行,谁能帮帮忙啊,谢谢啦~ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询