Guest User

Untitled

a guest
Jan 8th, 2013
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <vector>
  5. #include <string>
  6.  
  7. class Employee
  8. {
  9. public:
  10.     Employee(std::string const &name, unsigned age);
  11.     std::string const &name() const;
  12.     unsigned age() const;
  13.  
  14. private:
  15.     std::string mName;
  16.     unsigned mAge;
  17. };
  18.  
  19. Employee::Employee(std::string const &name, unsigned age)
  20.     : mName(name)
  21.     , mAge(age)
  22. {
  23. }
  24.  
  25. std::string const &Employee::name() const
  26. {
  27.     return mName;
  28. }
  29.  
  30. unsigned Employee::age() const
  31. {
  32.     return mAge;
  33. }
  34.  
  35. std::ostream &operator <<(std::ostream &out, Employee const &employee)
  36. {
  37.     return out << "Employee { name: " << employee.name() << ", age: " << employee.age() << " }";
  38. }
  39.  
  40. int main()
  41. {
  42.     std::vector<Employee> employees;
  43.     employees.push_back(Employee("John", 23));
  44.     employees.push_back(Employee("Anna", 22));
  45.  
  46.     copy(employees.begin(), employees.end(), std::ostream_iterator<Employee>(std::cout, "\n"));
  47. }
RAW Paste Data