title: C++ Writing to file or console by argument
body: <p>Ok, so I would like to do something I myself do find rather interseting .. I want an optional argument in my function and this argument would do two things;
  1. Decide whether the text is being printed to the console or to a file
  2. Print it to a file if that's the case, otherwise to console</p>
  
  <p>I want it to be in the same function because I want very efficient code.
  This is how I tried to solve it but obviously doesn't work</p>
  
  <pre><code>void Maze::Print_maze(std::string file = "no!ne") const{
      if (file != "no!ne")
          std::ofstream outfile(file);
      for (int i = 0; i &lt; Map.size(); i++)
      {
          for (int j = 0; j &lt; Map[i].size(); j++)
          {
              if (file == "no!ne")
                  std::cout &lt;&lt; Map[i][j];
              else
                  outfile &lt;&lt; Map[i][j];
          }
          if (file == "no!ne")
              std::cout &lt;&lt; std::endl;
          else
              outfile &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>For the curious ones .. 
  The code is from a maze project I'm working on, I'm generating a randomized maze, solving it and there's also the possibility of reading a maze from a file then solving it.
  Now all that remains is to print it to a file. But as said, rather than making two functions, I'd like to merge my normal print to console with print to a file. I'm just wondering how .. Is it possible?
  My "Map[][]" is a <code>vector &lt;vector&lt;char&gt; &gt;</code></p>