title: Reading multiple lines of strings from a file and storing it in string array in C++
body: <p>I have a class called StringList consisting of a constructor and a de-structor. What I am shooting for is for the ability of my program to retain its strings in the array even after it is not running. The way i want to do this is to have my constructor function read strings from a file and store them into my string array (str[]). My de-structor will save my current strings into my file. I am having trouble reading and storing from the file when memory is created. I want each word to be one element in the array.
  For example, in the file that is being read from, the strings are stored as such:</p>
  
  <pre><code>HELLO
  MOM
  DAD
  FOUR
  YELLOW
  </code></pre>
  
  <p>I want each word to be a slot. In other words. str[0] = HELLO, str[1]= MOM, str[2]=DAD and such.</p>
  
  <p>Here is my constructor function:</p>
  
  <pre><code>StringList::StringList()
  {
      numberOfStrings=0;
      str = new string[1000000];
  
  ifstream myfile ("Read.txt");
   if (myfile.is_open())
      {
          for (int i = 0; i &lt; 1000000; i++)
          {
              getline(myfile,str[i]);
              numberOfString++;
  
  
          }
  
          myfile.close();
      }
  
  
  }
  </code></pre>
  
  <p>Problem here is the for (int i=0; i&lt;100000;i++) line
  What this did is continue to fill each blank space into the element until it reached 100000.
  Same if i put i&lt;20, it would read all the contents and add blanks to fill to 20. Is there anyway to fill up to the amount of actual strings in the txt. file?</p>