Create widescreen char file

#ifndef UNICODE
#define UNICODE
#endif

#include <stdio.h>
int main()
{
    FILE* oFile;
    oFile = _wfopen(L"foo.txt",L"w");
    //*
    fwprintf(oFile,L"%s", L"ęłó☺☻♥♦•ń");
    fclose(oFile);
    return 0;
}

Why does this program create an ASCII file instead of UTF-16, although all the functions are wide ?!

foo.txt Contents:

za [question mark] ó [two questions ......] g [... four ...] ja [other ......] [five *?] [and the last]

It is irreversible.

fwprintf(oFile,L"%c%c%s",0xFE,0xFF,L"zażółć gęśłą jaźń ☺☻♥♦• ć");

Now it shows Chinese characters, regardless of whether the small or large byte order is set.

0
source share
2 answers

Assuming you are using MSVC, quote the documentation for _ wfopen (bold mines):

fopen , . _wfopen - fopen; _wfopen - . , _wfopen fopen . _wfopen .

:

fopen Unicode. Unicode, ccs, foken, .

fopen (& fp, "newfile.txt", "rw, ccs = encoding" );

UNICODE, UTF-8 UTF-16LE.

UTF-8. UTF-16BE, UTF-16LE UTF-8, MSVC .

#include <stdio.h>

int main()
{
    FILE* oFile;
    oFile = fopen("foo.txt","w, ccs=UTF-8");
    fwprintf(oFile,L"%s", L"ęłó☺☻♥♦•ń");
    fclose(oFile);
    return 0;
}

, Windows UTF-8:

C:\x>chcp
Active code page: 1252

C:\x>x

C:\x>type foo.txt
ęłó☺☻♥♦•ń
C:\Users\metolone\Desktop\x>chcp 65001
Active code page: 65001

C:\x>type foo.txt
ęłó☺☻♥♦•ń
+5

(char wchar_t) C ++ .

, , UTF16LE, , UTF16LE, , ++. UTF16LE ( iconv Windows) - .

NB1: "%ls".

NB2: , ASCII , .

NB3: "c", <cstdio> - ++, ++. ? ;)

+2

All Articles