CHAPTER2-8.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
源码类别:

STL

开发平台:

C/C++

  1. //文件名:CHAPTER2-8.cpp
  2. #include<iostream.h>
  3. #include<string.h>
  4. class  Student
  5. {
  6. friend  ostream& operator<<(ostream& ot, Student& popup);
  7. char  name[10];
  8. unsigned  int age;
  9. unsigned  long num;
  10. public:
  11.     Student(char *na, unsigned int al, unsigned long number):
  12.      age(al), num(number)
  13. {
  14.  strcpy(name, na);
  15.  }
  16. };
  17. ostream&  operator<<(ostream& ot, Student& popup)
  18. {
  19.       ot<<"Name"<<popup.name<<endl<<"Age"<<popup.age<<endl<<"Number:"
  20. <<popup.num<<endl<<"------------------------"<<endl;
  21.  return ot;
  22. }
  23. void  main()
  24. {
  25.     Student  a("Wang",18,1234),b("Zhao",19,4321),c("Liu",20,2134);
  26.     cout<<a<<b<<c;
  27. }