现有一个Student类,每个学生对象包含四个数据:学号、性别、姓名、成绩。
(性别:整数“0”表示男,整数“1”表示女)
编程实现对插入运算符(<<)和流提取符(>>)的重载,使它们能够对Student类对象直接进行输入和输出。
101 1 88 zhangsan
102 0 78 lisi
请输入学号,性别,分数,姓名
stud1:101 1 88 zhangsan
stud2:102 0 78 lisi
#include<iostream> using namespace std; class Student{ public: friend ostream& operator<<(ostream&,Student&); friend istream& operator>>(istream&,Student&); private: int num; int sex; string name; int score; }; //pdsu-c1 //pdsu-c1 int main(){ Student stud1,stud2; cout<<"请输入学号,性别,分数,姓名"<<endl; cin>>stud1; cout<<"stud1:"; cout<<stud1; cin>>stud2; cout<<"stud2:"; cout<<stud2; return 0; }
Anything about this OnlineJudge, Please Contact Administrator. Click add QQ
OJ system based on HUSTOJ Project , UI based on Twitter Bootstrap
Copyright 2016 ACM算法攻关部cnt: 48157
关于网站改版