title: sending different array types to different textfiles using one template c++
body: <p>Trying to get 3 different arrays of varying types to print to separate text files using one template.</p>
  
  <p>Here's what i have:</p>
  
  <pre><code>template &lt;class T&gt;
  void givetxt(T *a, const int n)
  {
      ifstream infile("C:\\.txt", ios::in | ios::app);
      for (int i = 0; i&lt;n; i++)
      {
          infile &gt;&gt; a[i];
      }
      infile.close();
  }
  
  template &lt;class T&gt;
  void savetxt(const T *a, const int n)
  {
      ofstream outfile("C:\\.txt", ios::out | ios::app);
      for (int i = 0; i&lt;n; i++)
          outfile &lt;&lt; a[i] &lt;&lt; endl;
      outfile.close();
  }
  
  int main()
  {
      const int n1 = 5, n2 = 7, n3 = 6;
      int a[n1];
      float b[n2];
      char c[n3];
  
  givetxt(a, n1);
  savetxt(a, n1);
  
  givetxt(b, n2);
  savetxt(b, n2);
  
  givetxt(c, n3);
  savetxt(c, n3);
  </code></pre>
  
  <p>right now it sends all of the array data to the .txt. Ideally i'll be able to get it to print to  <code>.inttxt</code>, <code>.floattxt</code> and  <code>.chartxt</code>. i'm not sure how to adjust the infile/outfile to allow for separate text files for the other arrays. i tried pointers but the template wouldn't allow me to relate <code>T a*</code> nor <code>const int n</code> to the variables i have in <code>main</code>. a push in the right direction would be most appreciated.</p>