title: How can one export a re-readable Neural Network object to a file in C++?
body: <p>The Neural Network program I am creating has hit a small... snag. Between <a href="http://www.cplusplus.com/forum/beginner/49924/" rel="nofollow noreferrer">http://www.cplusplus.com/forum/beginner/49924/</a> and <a href="https://stackoverflow.com/questions/8193590/how-to-write-a-2d-vector-into-a-binary-file">How to write a 2D vector into a binary file?</a>, I cannot identify an adequate means of printing this Network object to a file that can be read-back by the program for later use:</p>
  
  <pre><code>class Network {
      struct DNA {
          vector&lt;int&gt; size;
          // size[layer]
          vector&lt;vector&lt;double&gt;&gt; bias;
          // bias[layer][neuron]
          vector&lt;vector&lt;vector&lt;double&gt;&gt;&gt; weight;
          // weight[layer][neuron][input]
      };
  
      double fitness;
      DNA geno;
  }
  </code></pre>
  
  <p>I would hardly call this a problem... if each sub-vector was the same size. To compound the problem, these files must be human-readable for analysis. </p>
  
  <p>The most recently-attempted form is as follows:</p>
  
  <pre><code>    Layer0(2)
          Biases(2):0.2,-0.1
          Weights(2x2):0.1,0.2;-0.9,-0.22
      Layer1(3)
  </code></pre>
  
  <p>In parentheses are the sizes of the vectors required to read-in. The semicolon is meant to separate the weights associated with each neuron. I got lost when trying to devise a method of reading the weights.</p>
  
  <pre><code>    string tmp;
  
      // get weights.
      getline(netFile, tmp, '(');
      getline(netFile, tmp, 'x');
      weight.resize(atof(tmp.c_str()));
  
      for (int i = 0; i &lt; weight.size() - 1; i++) {
          vector&lt;double&gt; tWeight;
          getline(netFile, tmp, ')');
          tWeight.resize(atof(tmp.c_str()));
          getline(netFile, tmp, ':');
          for (int j = 0; j &lt; tWeight.size() - 1; j++) {
              getline(netFile, tmp, ',');
  
              // THIS IS WHERE I GOT LOST.
          }
      }
  </code></pre>
  
  <p>My plan was to get a 2-D vector to push_back upon the weight vector of "geno."</p>
  
  <p>A little help would be appreciated. If there is a means of writing the entire object (or at least, the structure) in binary, and reading it in, I can easily manage with writing 2 files (the network, and the human-readable source).</p>