title: How to write custom datatype (std::array filled with std::pairs) to a filestream
body: <p>I am quite new to c++ and I am building a model studying certain mutations in genes. My "genes" are defined as a function of two doubles, a and b. A single gene is saved in a std::pair format. The whole genome consists of four of these genes collected in a std:array. </p>
  
  <p>I perform some changes on the genes and want to write the information in a text file for analysis. The way I have currently implemented this is tedious. I have separate functions (8 in total) which collect the information like g[i].first, g[i[.second etc. for every i in the array. I feel this could be done much more efficiently. </p>
  
  <p>Relevant code:</p>
  
  <p>Declaration of data type: </p>
  
  <pre><code>using gene = std::pair&lt;double, double&gt;;
  using genome = std::array&lt;gene, 4&gt;;
  </code></pre>
  
  <p>Function in which I create a genome called g:</p>
  
  <pre><code>genome Individual::init_Individual()
  {
      double a1, a2, a3, a4 = -1.0;
      double b1, b2, b3, b4 = 0.0;
      gene g1{ a1,b1 };
      gene g2{ a2,b2 };
      gene g3{ a3,b3 };
      gene g4{ a4,b4 };
      genome g{g1,g2,g3,g4};
      return g;
  }
  </code></pre>
  
  <p>Example of collect function:</p>
  
  <pre><code>double get_Genome_a1() { return g[0].first; };
  </code></pre>
  
  <p>Function in which I write information to a text file:</p>
  
  <pre><code>void Individual::write_Statistics(unsigned int &amp;counter)
  {
      //Generate output file stream
      std::ofstream ofs;
      ofs.open("data.txt", std::ofstream::out | std::ofstream::app);    
      ofs &lt;&lt; counter &lt;&lt; std::setw(14) &lt;&lt; get_Genome_a1() &lt;&lt;     std::setw(14)
          &lt;&lt; get_Genome_a2() &lt;&lt; std::setw(14) &lt;&lt; get_Genome_b1() &lt;&lt;
          std::setw(14) &lt;&lt; get_Genome_b2() &lt;&lt; "\n";
  }
  ofs.close();
  </code></pre>
  
  <p>}</p>
  
  <p>etc, etc. So the final result of my data file in this example looks like this:</p>
  
  <p>1   a1    a2    b1   b2</p>
  
  <p>2   a1    a2    b1   b2</p>
  
  <p>3   a1    a2    b1   b2</p>
  
  <p>etc, etc.</p>
  
  <p>My question:</p>
  
  <ol>
  <li>I am currently storing the two doubles in a std::pair, which I collect in a std::array. Is this an efficient storage mechanism or can this be improved?</li>
  <li>Is there a way to directly reference an individual element from my custom data type "genome" using only one function to write every element away in the exact same manner as I am doing now (with fourteen spaces between every element)? Something in pseudocode like: get_Genome() {return g;};, and when you call it you can specify the element like: get_Genome([0].first) which would be the first value stored in the first pair of the array, for example. </li>
  </ol>
  
  <p>Happy to learn, any insight is appreciated. </p>