title: Reading file with istream
body: <p>I am working on a project which involves polymorphism and inheritance.</p>
  
  <p>lets assume that the hierarchy of the classes used in the project are:</p>
  
  <pre><code>Media ----&gt; Book ----&gt; MediaRegistry 
  </code></pre>
  
  <p>and the declaration of each class are as follows: (the classes have been narrowed down to the members which I have problem)</p>
  
  <pre><code>class Media
  {
  public:
      Media();
      Media(int id, string content);  
      virtual void input(istream&amp; in) = 0;
      friend istream&amp; operator&gt;&gt;(istream&amp; in, Media&amp; media);
  
  protected:                          
      string _mediaTitle;
      int _id;
  };
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>istream&amp; operator&gt;&gt;(istream&amp; in, Media&amp; media) 
  {
      media.input(in);
      return in;
  }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>class Book:public Media     // Inherits from abstract base class Media
  {
  public:
      Book();
      Book(int id, string title, int nrOfPages); // Constructor 
      void input(istream&amp; in);
  
  private:
      int _nrOfPages;
  };
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>void Book::input(istream&amp; in)
  {
      in &gt;&gt; _id &gt;&gt; _mediaTitle &gt;&gt; _nrOfPages;
  }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>class MediaRegistry
  {
  public:
      MediaRegistry();
      int addMedia(Media*);       
      int loadMedia();
  
  private:
      static const int MAX = 10;
      //Media* _pMedias[MAX];     // Vector for MAX numbers of Media pointers
      std::vector&lt;Media*&gt; _pMedias;
      int _nrOfMedias;                // _nrOfMedias == MAX when registry is full
      ifstream inFile;
      ofstream outFile;
      string path = ".\\data.txt";
  };
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>int MediaRegistry::loadMedia()
  {
      inFile.open(path.c_str());
      while (!inFile.eof())
      {
          int mediaType = 0;
          inFile &gt;&gt; mediaType;
          if (inFile.eof())
              break;
          Media* media = nullptr;
          media = new Book();
          inFile &gt;&gt; *media;
          addMedia(media);
       }
      inFile.close();
      return 0;
  }
  </code></pre>
  
  <p>Now in the <code>data.txt</code>, as title of the media, if I have space between the words (i.e, "The Clown" in stead of e.g "the-Clown"), the program encounters a problem in this member function <code>istream&amp; operator&gt;&gt;(istream&amp; in, Media&amp; media)</code>. I cannot understand, however, I debugged it many times to track the problem. In fact, I want my program could be able to get a string with space in it, but it doesn't do that now??  </p>