forked from Light-City/CPlusPlusThings
-
Notifications
You must be signed in to change notification settings - Fork 1
/
输入输出重载.cpp
41 lines (35 loc) · 758 Bytes
/
输入输出重载.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
using namespace std;
#include<cstring>
class Sales{
private:
char name[10];
char id[18];
int age;
public:
Sales(char *Name,char *ID,int Age);
friend Sales &operator<<(ostream &os,Sales &s);
friend Sales &operator>>(istream &is,Sales &s);
};
Sales::Sales(char *Name,char *ID,int Age){
strcpy(name,Name);
strcpy(id,ID);
age=Age;
}
Sales &operator<<(ostream&os,Sales &s){
os<<s.name<<"\t"<<s.id<<"\t"<<s.age<<endl;
return s;
}
Sales &operator>>(istream&is,Sales &s){
cout<<"输入雇员的姓名,身份证,年龄:\n";
is>>s.name>>s.id>>s.age;
}
int main(int argc, char const *argv[])
{
Sales s("张三","15611",26);
cout<<s;
cin>>s;
cout<<s;
system("pause");
return 0;
}