title: C++ Outputting strings from a .txt file in to a dynamic array outside of a member methods local scope
body: <p>To start with, is what I'm asking possible?</p>
  
  <p>I currently have a program with one member method (Read) that reads in strings from a .txt file locally in one member method and just outputs the same data to the console. Now as it stands I can't do anything with the contents of the array, however I need the data to use in a Write method and wherever else in my code. I have used a dynamic C style array because that is what is required of me, no vector's etc are permitted. A solution or any general direction would be fantastic!</p>
  
  <p>My structure is comprised of one Main.cpp, an ArrayStorage.cpp class definition and an ArrayStorage.h header file.</p>
  
  <p>My code is below:</p>
  
  <p><strong>ArrayStorage.cpp</strong></p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;ostream&gt;
  #include &lt;string&gt;
  #include "ArrayStorage.h"
  using namespace std;
  
  
  void ArrayStorage::read(ifstream &amp;fin1)
  {
      int index = 0;
      int arrayLength = 0;
      string firstWord;
  
      if(fin1.is_open())
          {
              fin1 &gt;&gt; firstWord;
              fin1 &gt;&gt; arrayLength;
  
              string* arrayOfWords;
              arrayOfWords = new string[arrayLength];
  
              while(!fin1.eof())
              {
                  fin1 &gt;&gt; arrayOfWords[index];
                  cout &lt;&lt; arrayOfWords[index];
                  cout &lt;&lt; "\n";
                  index++;
              }
  
              delete [] arrayOfWords;
  
              fin1.close();
          }
  }
  
  void ArrayStorage::write(ofstream &amp;out1)
  {
      //fout.close();
  }
  </code></pre>
  
  <p><strong>ArrayStorage.h</strong></p>
  
  <pre><code>#include &lt;fstream&gt; // Reading/Writing from file requires this standard library.
  #include &lt;iostream&gt; // Needed for cin and cout
  #include &lt;ostream&gt; // Needed for outputting to output file
  #include &lt;string&gt; // Needed for string values
  using namespace std;
  
  #pragma once
  
  class ArrayStorage
  {
  private:
  
  
  
  public:
  
      void read(ifstream &amp;fin1); //reads data from a file
      void write(ofstream &amp;out1); //output data to an output stream(ostream)
      bool exists(); //return true or false depending whether or not a given word exists
      void stdExists(); //^^ use either std::count() or std::find() inside here
  
  
  };
  </code></pre>
  
  <p>Main.cpp</p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  #include "ArrayStorage.h"
  #include "LinkedListStorage.h"
  
  
  int main(int argc, char **argv) {
  
  string find = "pixel";
  
  ifstream fin1("ACW2_data.txt");
  ofstream out1("1-In-SortedRead.txt");
  
  if(!fin1.is_open()) 
  {
      cout &lt;&lt; "FAIL" &lt;&lt; endl;
      return 1;
  }
  
  ArrayStorage arrayStorage1;
  
  // read in values into data structure
  arrayStorage1.read(fin1);
  
  // output values in data structure to file
  arrayStorage1.write(out1);
  
  fin1.close();
  out1.close();
  return(0);
  }
  </code></pre>