c++ overloading operator << of ofstream for Report/Logger class
<p>I'm trying to create a report/logger Class in c++.</p>

<p>I want to have in the main an object called Report and apply to this class the operator &lt;&lt; to write to file multiple strings just like ofstream does.</p>

<p>So instead of using the following code:</p>

<pre><code>  ofstream myfile ("d://example.txt");
  if (myfile.is_open())
  {
    myfile &lt;&lt; "This is a line.\n" &lt;&lt; "Heya!!!" &lt;&lt; endl;
    myfile.close();
  }
</code></pre>

<p>I would like to have something like the following :</p>

<pre><code>  Report rLogger ("d://example.txt"); // Report C'tor (const string&amp; s)
  logger &lt;&lt; "This is a line.\n" &lt;&lt; "Heya!!!" &lt;&lt; endl;
// the destructor of rLogger will close the file when it dies...
</code></pre>

<p>I just can't find out a way to write the operator &lt;&lt; as a member function which seems exactly what I need here. The only way I can use the operator &lt;&lt; is as friend which isn't helpful in this case. Can someone give me an idea how can I implement it as above?</p>

<p>Thank in advance,
Guy</p>
