65,211
社区成员
发帖
与我相关
我的任务
分享
#ifndef _TTT_H_
#define _TTT_H_
#include <iostream>
#include <string>
class student
{
public:
std::string name;
int num, score;
student(std::string na = "xx", int n = 0, int s = 0) : name(na), num(n), score(s) {}
friend std::istream &operator>>(std::istream &, student &);
friend std::ostream &operator<<(std::ostream &, student &);
};
#endif#include <iostream>
#include <string>
#include "TTT.h"
using namespace std;
istream &operator>>(istream &a1,student &a2)
{
cout << "please enter name:" << endl;
a1 >> a2.name;
cout << "please enter your school number:" << endl;
a1 >> a2.num;
cout << "please enter your score:" << endl;
a1 >> a2.score;
cout << endl;
return a1;
}
ostream &operator<<(ostream &a1,student &a2)
{
a1 << "result as below:" << endl << a2.name << endl << a2.num << endl << a2.score << endl;
return a1;
}
int main()
{
student x, y;
cin >> x;
cout << x;
cin >> y;
cout << y;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class student;
istream & operator >>(istream &,student &);
ostream & operator <<(ostream &,student &);
class student {
private:
string name;
int num,src;
public:
student(string na="xx",int n=0,int s=0):name(na),num(n),src(s){}
friend istream & operator >>(istream &,student &);
friend ostream & operator <<(ostream &,student &);
};
istream& operator >>(istream& a1,student& a2) {
cout <<"请输入姓名:" <<endl;
a1>>a2.name;
cout <<"请输入学号:" <<endl;
a1>>a2.num;
cout <<"请输入分数:" <<endl;
a1>>a2.src;
cout <<endl;
return a1;
}
ostream & operator <<(ostream &a1,student &a2) {
a1 <<"结果如下:" <<endl <<a2.name <<endl <<a2.num <<endl <<a2.src <<endl;
return a1;
}
int main() {
student x,y;
cin>>x;
cout <<x;
cin>>y;
cout <<y;
return 0;
}