blob: d0a8f9edacfd233a3a9cc5a26720123c5b1d2e2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include <stdio.h>
#include <windows.h>
#include <fcntl.h>
#include <io.h>
/* This program demonstrates Unicode UTF-16 printed text redirected to a
correct UTF-16 file.
.\testu16.exe > out.txt
*/
int main () {
int prevmode;
prevmode = _setmode(_fileno(stdout), _O_U16TEXT);
/* We need to print an UTF-16 BOM for correct redirection in PowerShell. */
fwprintf(stdout, L"\xfeff");
fwprintf(stdout,L"one\n");
fwprintf(stdout,L"two\n");
fwprintf(stdout,L"three\n");
/* Flushing stdout is required to get correct UTF-16.
This is required for both CMD.exe and PowerShell. */
fflush(stdout);
_setmode(_fileno(stdout), prevmode);
return 0;
}
|