title: Reading words from a file into dynamically allocated array
body: <p>So I am trying to read string data from a file into a dynamically allocated array, but I cannot seem to get the correct code for doing so. I have below a code using an array of a preset size but that would not be efficient, hence why I want to use dynamic memory allocation. I know I have to use pointers but I am fairly new to the concept so any help would be greatly appreciated.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;iomanip&gt;
  #include &lt;cstdlib&gt;
  #include &lt;algorithm&gt;
  #include &lt;cctype&gt;
  #include &lt;string&gt;
  
  #define SIZE 100
  
  using namespace std;
  
  void loadData();
  
  int main()
  {
      loadData();
      return 0;
      {
  
          string fileName;
          std::string wordArray[SIZE];
          cout &lt;&lt; &quot;Please enter the name of the text file you want to process followed by '.txt': &quot; &lt;&lt; endl;
          cin &gt;&gt; fileName;
  
          ifstream dataFile(fileName);
          if (dataFile.fail()) {
              cerr &lt;&lt; fileName &lt;&lt; &quot; could not be opened.&quot; &lt;&lt; endl; //error message if file opening fails
              exit(-1);
          }
          while (!dataFile.eof()) {
              for (int i = 0; i &lt; SIZE; i++) {
                  dataFile &gt;&gt; wordArray[I];
                  for (std::string&amp; s : wordArray) //this for loop transforms all the words in the text file into lowercase
                      std::transform(s.begin(), s.end(), s.begin(),
                          [](unsigned char c) { return std::tolower(c); });
              }
          }
          dataFile.close();
      }
  }
  </code></pre>