How to convert CString to ofstream?
<p>I have a few CString variables that I wish to output to an ofstream, but I can't seem to figure out how to do so. Here's some example code.</p>

<p>I have unicode enabled in VS 2005</p>

<p>CODE:
     ofstream ofile;
      CString str = "some text";</p>

<pre><code>  ofile.open(filepath);
   ofile &lt;&lt; str; // doesn't work, gives me some hex value such as 00C8F1D8 instead
    ofile &lt;&lt; str.GetBuffer(str.GetLength()) &lt;&lt; endl; // same as above
     ofile &lt;&lt; (LPCTSTR)str &lt;&lt; endl; // same as above

   // try copying CString to char array
  char strary[64];
  wcscpy_s(strary, str.GetBuffer()); // strary contents are correctly copied
  ofile &lt;&lt; strary &lt;&lt; endl ; // same hex value problem again!
</code></pre>

<p>Any ideas? Thanks!</p>
