title: Convert System::String to std::string in UTF8, which later converted to char* as c_str
body: <p>I have a <code>System::String^</code> variable in C++ code. This variable should be converted to <code>std::string</code> which is later converted to <code>const char*</code> via <code>c_str</code>.</p>
  
  <pre><code>// original string
  System::String^ path = ...;
  
  // convert to std::string
  msclr::interop::marshal_context context;
  std::string filename(context.marshal_as&lt;std::string&gt;(path));
  
  // call API function that internally connects to sqlite3 using sqlite3_open as
  //   sqlite3_open(filename.c_str())
  // https://www.sqlite.org/c3ref/open.html - 
  //  const char *filename,   /* Database filename (UTF-8) */
  doCalculation(filename)
  </code></pre>
  
  <p>It works well with the ASCII paths, but fails if the path contains non-latin characters.</p>
  
  <p>So Somehow I need to convert marshalled std::string from current implementation (ASCII?) to UTF8.</p>
  
  <p>I've tried </p>
  
  <pre><code>    std::wstring dbPath(context.marshal_as&lt;std::wstring&gt;(path));
      std::wstring_convert&lt;std::codecvt_utf8_utf16&lt;wchar_t&gt;, wchar_t&gt; convert;
      std::string dbPathU8 = convert.to_bytes(dbPath);
  </code></pre>
  
  <p>but it does not work.</p>