title: Printing to file using Gecode
body: <p>I am doing a Gecode project and the code should output a file which looks like the following:</p>
  
  <pre><code>n: 17
  x: {0, 0, 16, 18, 17, 31, 32, 0, 34, 10, 30, 37, 38, 30, 30, 10}
  y: {0, 27, 28, 14, 0, 31, 20, 17, 11, 17, 0, 0, 6, 7, 11, 25}
  s: 43
  runtime: 0.137
  failure: 127
  </code></pre>
  
  <p>The above is an example of what the code should output. I have tried to do the following code:</p>
  
  <pre><code>virtual void
  print(std::ostream&amp; os) const {
      string filename = "project1-t15-n" + n + ".txt";
  
      ofstream myfile;
      myfile.open (filename);
  
      myfile &lt;&lt; "n: " &lt;&lt; n &lt;&lt; std::endl;
      myfile &lt;&lt; "x: {";
      for (int i = 0; i &lt; x.size(); i++) {
          if (i != 0) {
              myfile &lt;&lt; ", ";
          }
          myfile &lt;&lt; x[i];
      }
      myfile &lt;&lt; "}" &lt;&lt; std::endl;
      myfile &lt;&lt; "y: {";
      for (int i = 0; i &lt; y.size(); i++) {
          if (i != 0) {
              myfile &lt;&lt; ", ";
          }
          myfile &lt;&lt; y[i];
      }
      myfile &lt;&lt; "}" &lt;&lt; std::endl;
      myfile &lt;&lt; "s: " &lt;&lt; s &lt;&lt; std::endl;
  
      //???????????????????????????????? print runtime and failures
  
      myfile.close();
  }
  </code></pre>
  
  <p>I know that n, s, x and y are correct, but I have two questions:</p>
  
  <p>1: Is <code>print(std::ostream&amp; os) const</code> the correct usage when printing to a file?</p>
  
  <p>2: How can you get runtime and failures from the Gecode output? Their build in print function does this.</p>