title: Open utf8 encoded filename in c++ Windows
body: <p>Consider the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost\locale.hpp&gt;
  #include &lt;Windows.h&gt;
  #include &lt;fstream&gt;
  
  std::string ToUtf8(std::wstring str)
  {
      std::string ret;
      int len = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0, NULL, NULL);
      if (len &gt; 0)
      {
          ret.resize(len);
          WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.length(), &amp;ret[0], len, NULL, NULL);
      }
      return ret;
  }
  
  int main()
  {
      std::wstring wfilename = L"D://Private//Test//एउटा फोल्दर//भित्रको फाईल.txt";
      std::string utf8path = ToUtf8(wfilename );
      std::ifstream iFileStream(utf8path , std::ifstream::in | std::ifstream::binary);
      if(iFileStream.is_open())
      {
          std::cout &lt;&lt; "Opened the File\n";
          //Do the work here.
      }
      else
      {
          std::cout &lt;&lt; "Cannot Opened the file\n";
  
      }
      return 0;
  
  }
  </code></pre>
  
  <p>If I am running the file, I cannot open the file thus entering into the <code>else</code> block. Even using <code>boost::locale::conv::from_utf(utf8path ,"utf_8")</code> instead of <code>utf8path</code> doesn't work. The code works if I consider using <code>wifstream</code> and using <code>wfilename</code> as its parameter, but I don' want to use <code>wifstream</code>. Is there any way to open the file with its name <code>utf8</code> encoded? I am using <code>Visual Studio 2010</code>.</p>