title: Create structs with names generated at runtime and refer to them within program
body: <p>I have a set of datafiles stored within a directory.
  eg.</p>
  
  <pre><code>./FT/Fourier_1
  ./FT/Fourier_2
  ./FT/Fourier_3
  ...
  </code></pre>
  
  <p>My code initially generates a list of the paths to these files.</p>
  
  <pre><code>std::string fileStringSearch="Fourier";
  std::stringstream resultFileName;
  std::vector&lt;std::string&gt; fileList;
  int numLines=0;
  
  DIR *parentDirPointer;
  struct dirent *dp;
  
  if ((parentDirPointer = opendir("FT")) == NULL)
  {
      std::cout &lt;&lt; "Unable to open the parent (FT) directory" &lt;&lt; std::endl;
      return(3);
  }
  
  while ((dp = readdir(parentDirPointer)) != NULL)
  {
      std::string testFileName = dp-&gt;d_name;
      if (testFileName.find(fileStringSearch) != std::string::npos)
      {
          resultFileName &lt;&lt; "FT/" &lt;&lt; dp-&gt;d_name;
          std::string blahblah=resultFileName.str();
          fileList.push_back(blahblah);
          numLines++;
          resultFileName.str(std::string());
          resultFileName.clear();
      }
  };
  
  sort(fileList.begin(),fileList.end());
  
  for (unsigned n=0; n&lt;fileList.size(); ++n)
  {
      resultFileName &lt;&lt; fileList.at(n) &lt;&lt; std::endl;
  }
  FTFilePaths = resultFileName.str();
  </code></pre>
  
  <p>I then want to read data from each file and store it in some format which I can later read, use in functions, etc.</p>
  
  <p>My current thought is a struct - I have:</p>
  
  <pre><code>struct Wavenum_struct {
      std::string name;
      double timestep;
      double indexToK_Multiplier;
      std::vector&lt;double&gt; Amp_k;
      std::vector&lt;double&gt; dFTdt_prev_to_this;
      }
  </code></pre>
  
  <p>and at a later point in my program I read these files like :</p>
  
  <pre><code>for (int lineCounter=0; lineCounter &lt; numLines; lineCounter++)
      {
          getline(readPath, FilePathLine);
          c = FilePathLine.c_str();
          readFile.open(c);
          extern Wavenum_struct c;
          c.name = FilePathLine;
          //print_name(c);
          while(getline (readFile, lineToRead))
          {
              readFile &gt;&gt; value;
              c.Amp_k.push_back(value);
          }
          //print_amps(c);
  
      }
  </code></pre>
  
  <p>The commented out print_amps(c); will work just fine with a function something like:</p>
  
  <pre><code>void print_amps(struct Wavenum_struct t)
  {
      for(int i=0; i&lt;t.Amp_k.size(); i++)
      {   
          std::cout &lt;&lt; i &lt;&lt; ": " &lt;&lt; t.Amp_k[i] &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>but this obviously prints the amplitudes of every struct, and only once. If I want to refer to specific structs later in the program, and print them selectively, (or not print them, but use them for some function) eg</p>
  
  <pre><code>void dFTdt(struct Wavenum_struct t_i, struct Wavenum_struct t_i1)
  {
      int numWavenums = t_i.Amp_k.size();
      double dt = t_i1.timestep - t_i.timestep;
      double dFTdt[numWavenums];
      for (int k=0; k&lt;numWavenums; k++)
      {
          dFTdt[k] = (t_i1.Amp_k[k] - t_i.Amp_k[k])/dt;
      }
      t_i1.dFTdt_prev_to_this.assign(dFTdt, dFTdt+numWavenums);
  }
  </code></pre>
  
  <p>then I can't seem to get anywhere, since c returns to being recognised as a const * char outside of the for loop, and anything I've tried like:</p>
  
  <pre><code>print_amps(reinterpret_cast&lt;Wavenum_struct*&gt;("FT/Fourier_1"));
  </code></pre>
  
  <p>refuses to compile.</p>
  
  <p>I assume that what I need might involve pointers to functions and print_name() as a function of the struct, but this doesn't seem likely to help me with my void dFTdt() function, and I still don't know how to refer to a given struct once c no longer gives the name of that struct.</p>
  
  <p>Is this in any way possible?</p>