title: C++/CLI String Conversions
body: <p>I found this really nice piece of code that converts a string to a <code>System:String^</code> as in:</p>
  
  <pre><code>System::String^ rtn = gcnew String(move.c_str());  // 'move' here is the string
  </code></pre>
  
  <p>I'm passing rtn back to a C# program. Anyways, inside the function where this code exists, I'm passing in a <code>System::String^</code>. I also found some code to convert a <code>System:String^</code> to a string using the following code:</p>
  
  <pre><code>pin_ptr&lt;const wchar_t&gt; wch = PtrToStringChars(cmd);  // 'cmd' here is the System:String          
  size_t convertedChars = 0;
  size_t  sizeInBytes = ((cmd-&gt;Length + 1) * 2);
  errno_t err = 0;
  char *ch = (char *)malloc(sizeInBytes);
  
  err = wcstombs_s(&amp;convertedChars,ch, sizeInBytes,wch, sizeInBytes);
  </code></pre>
  
  <p>Now I can use 'ch' as a string.</p>
  
  <p>This, however, seems to be alot more work than converting the other way using the <code>gcnew</code>. So, at last my question is, is there something out there that will convert a <code>System::String^</code> to string using a similar fashion as with the gcnew way?</p>