1

I have a problem with wide stream output. My primary concern is wofstream but wcout doesn't work properly either. So it doesn't produce output besides Latin characters. That is

#include <string>
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
wstring wstr = L"Андрей";
wofstream fout(L"C:\\Work\\report.htm");
wcout << wstr << L"Привет мир";
fout << wstr << L"Привет мир";
fout.close();
}

Produces no output, the file stays 0 byte long.

Mixing like wcout<<L"zuhщзг" prints just "zuh", ignores the rest.

I use MVS 2013 with Intel C++ Composer 14.0

EDIT: Windows Unicode C++ Stream Output Failure describes similar problem. But I don't quite understand how the solution works. MVS/Windows use UTF-16 for wide strings. and I would like they to be written in the file, as is, that is utf-16, without any unnecessary conversion

Community
  • 1
  • 1
Andrey Pro
  • 501
  • 1
  • 10
  • 22
  • @MichaelUrman Ok, that would fix console, but as I stated the main problem is file output – Andrey Pro May 23 '14 at 14:11
  • Ah, you're right. It's not a duplicate of http://stackoverflow.com/questions/2492077/output-unicode-strings-in-windows-console-app, though its problems overlap somewhat. Check http://stackoverflow.com/questions/207662/writing-utf16-to-file-in-binary-mode for another approach. – Michael Urman May 24 '14 at 13:30

0 Answers0