title: How do I create 3 types of objects(movie, book & journal) from this text file and then display it?
body: <p>So far I can only create one type of object - books, can someone explain how can I create movie and journal objects?
  This is what I have done so far:</p>
  <pre class="lang-cpp prettyprint-override"><code>    #include &lt;iostream&gt;
      #include &lt;fstream&gt;
      #include &lt;sstream&gt;
      #include &lt;vector&gt;
  
      using namespace std;
  
      struct Item {
        string type;
        string id;
        string title;
        string year;
      };
  
      struct Movie : Item {
        string director;
      };
  
      struct Book : public Item {
        string author;
        string pages;
      };
  
      struct Journal : public Item {
        string volume;
        string number;
      };
  
      void readBooks(ifstream&amp; input, vector&lt;Book&gt;&amp; books)
      {
        string line;
        while(getline(input, line)) {
          istringstream iss(line);
          Book book;
          getline(iss, book.type, ',');
          getline(iss, book.id, ',');
          getline(iss, book.title, ',');
          getline(iss, book.year, ',');
          getline(iss, book.author, ',');
          getline(iss, book.pages, ',');
          books.push_back(book);
          cout &lt;&lt; &quot;Type: &quot; &lt;&lt; book.type &lt;&lt; endl;
          cout &lt;&lt; &quot;ID: &quot; &lt;&lt; book.id &lt;&lt; endl;
          cout &lt;&lt; &quot;Title: &quot; &lt;&lt; book.title &lt;&lt; endl;
          cout &lt;&lt; &quot;Year: &quot; &lt;&lt; book.year &lt;&lt; endl;
          cout &lt;&lt; &quot;Author: &quot; &lt;&lt; book.author &lt;&lt; endl;
          cout &lt;&lt; &quot;Number of Pages: &quot; &lt;&lt; book.pages &lt;&lt; endl &lt;&lt; endl;
      }
      }
  
      int main() {
      
      vector&lt;Book&gt; books;
      ifstream input(&quot;/Users/nethmi/Desktop/library.txt&quot;);
      if(input.is_open()){
          readBooks(input, books);
      }
      return 0;
      }
  </code></pre>
  <p>This the output I get:
  <img src="https://i.stack.imgur.com/MH7AR.png" alt="enter image description here" /></p>
  <h2>And this is the data in the text file:</h2>
  <p>Movie,200,Remember The Alamo,1945,George Smith</p>
  <p>Movie,203,Lord of the ring: the fellowship of the ring,2001,Pete Jackson</p>
  <p>Movie,206,Lord of the ring: the two towers,2002,Peter Jackson</p>
  <p>Movie,210,Going for the Touchdown,1984,Frank Madden</p>
  <p>Movie,211,Martian Hairdresser,1992,Debbie Gold</p>
  <p>Book,231,How to Make Money,1987,Phil Barton,324</p>
  <p>Book,240,Garden Projects At Home,1998,Mary Freeman,164</p>
  <p>Book,202,The Haunted House Mystery,1996,Bert Morgan,53</p>
  <p>Journal,207,ACM,2009,6,8</p>
  <p>Journal,212,ACM,2010,5,8</p>
  <p>Journal,215,J of Logic,2008,23,14</p>
  <p>Journal,281,J of AI,2009,35,1</p>
  <hr />
  <p>I deleted the movie and journal data to check if it works (just for the book object) and it does, but I don't know how to create 3 types of objects.</p>
  <p>Hope this is clear.</p>