title: Reading UTF-16 file in c++
body: <p>I'm trying to read a file which has UTF-16LE coding with BOM.
  I tried this code</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;locale&gt;
  #include &lt;codecvt&gt;
  
  int main() {
  
    std::wifstream fin("/home/asutp/test");
    fin.imbue(std::locale(fin.getloc(), new std::codecvt_utf16&lt;wchar_t, 0x10ffff, std::consume_header&gt;));
    if (!fin) {
      std::cout &lt;&lt; "!fin" &lt;&lt; std::endl;
      return 1;
    }
    if (fin.eof()) {
      std::cout &lt;&lt; "fin.eof()" &lt;&lt; std::endl;
      return 1;
    }
    std::wstring wstr;
    getline(fin, wstr);
    std::wcout &lt;&lt; wstr &lt;&lt; std::endl;
  
    if (wstr.find(L"Test") != std::string::npos) {
      std::cout &lt;&lt; "Found" &lt;&lt; std::endl;
    } else {
      std::cout &lt;&lt; "Not found" &lt;&lt; std::endl;
    }
  
    return 0;
  }
  </code></pre>
  
  <p>The file can contain Latin and Cyrillic. I created the file with a string "Test тест". And this code returns me</p>
  
  <pre><code>/home/asutp/CLionProjects/untitled/cmake-build-debug/untitled
  
  Not found
  
  Process finished with exit code 0
  </code></pre>
  
  <p>I'm on Linux Mint 18.3 x64, Clion 2018.1</p>
  
  <p>Tried</p>
  
  <ul>
  <li>gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)</li>
  <li>clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)</li>
  <li>clang version 5.0.0-3~16.04.1 (tags/RELEASE_500/final)</li>
  </ul>