Advertisement
Tavxela

Untitled

Apr 24th, 2021
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. class Journal {
  9. public:
  10.     static string publisher;
  11.     string title;
  12.     string month;
  13.  
  14.     bool was_published_in(string month)
  15.     {
  16.         return this->month == month;
  17.     }
  18.  
  19.     Journal(istream& input)
  20.     {
  21.         this->operator>>(input);
  22.     }
  23.  
  24.  
  25.     void operator >>(istream& input)
  26.     {
  27.         input >> title;
  28.         input >> month;
  29.     }
  30. };
  31.  
  32. string Journal::publisher = "Elsevier";
  33.  
  34. ostream& operator <<(ostream& output, const Journal& object)
  35. {
  36.     return output << object.publisher << ' ' <<  object.title;
  37. }
  38.  
  39.  
  40. int main()
  41. {
  42.     fstream journals_file;
  43.  
  44.     journals_file.open("./journals.txt");
  45.     if (journals_file.is_open())
  46.     {
  47.         while (not journals_file.eof()) {
  48.             Journal tmp(journals_file);
  49.             if (tmp.was_published_in("February"))
  50.                 cout << tmp << endl;
  51.         }
  52.        
  53.     }
  54.     journals_file.close();
  55.  
  56.     return EXIT_SUCCESS;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement