Simple utility for testing the effect of different ways of generating text output.
encexp method mode [options...]
method defines the basic API category used and is one of:
winapi
: use Windows API methods (OpenFile()
,WriteFile()
,WriteConsole()
)posix
: use ‘POSIX style’ methods (_open()
,_write()
)unformatted
: use unformatted C stream I/O (fopen()
andfwrite()
)formatted
: use formatted C stream I/O (fopen()
andfprintf()
)unformatted++
: use unformatted C++ stream I/O (std::basic_ostream
and.write()
)formatted++
: use formatted C++ stream I/O (std::basic_ostream
and<<
)
mode selects different options within the API and is one of:
binary
: data as non-text binarytext
: data as narrow-character (8-bit) textwide
: data as wide-character (16-bit) textunicode
: output as ‘Unicode mode’; this is something variously described in Microsoft documentation as accepting wide-character (i.e. UTF-16) and converted internally to UTF-8wideunicode
: even less well documented, vaguely described as accepting UTF-16 and outputting UTF-16
Not every mode is supported by every method (as described in the table, below).
Supported options are:
cp####
: set the Console Output Code Page (through a call toSetConsoleOutputPage()
) prior to generating outputl####
: set the locale prior to generating output; the specific method used depends on the selected Method and isfile
: output directly to a file namedoutput
as opposed to standard output
Method | Binary | Text | Wide | Unicode | Wide Unicode |
---|---|---|---|---|---|
Windows API | WriteFile() | WriteConsoleA() | WriteConsoleW() | n/a | n/a |
‘POSIX’ style | _open(_O_BINARY) | _open(_O_TEXT) | _open(_O_WTEXT) | _open(_O_U8TEXT) | _open(_O_U16TEXT) |
C unformatted | fopen("wb") fwrite() | fopen("w") fwrite() | fopen("w,ccs=unicode") fwrite() | fopen("w,ccs=utf-8") fwrite() | fopen("w,ccs=utf-16le") fwrite() |
C formatted | fopen("wb") fprintf() | fopen("w") fprintf() | fopen("w,ccs=unicode") fwprintf() | fopen("w,ccs=utf-8") fwprintf() | fopen("w,ccs=utf-16le") fwprintf() |
C++ unformatted | ostream(ios::binary) .write() | ostream() .write() | wostream() .write() | fopen("w,ccs=utf-8") wostream(FILE) .write() | fopen("w,ccs=utf-16le") wostream(FILE) codecvt_utf16 .write() |
C++ formatted | ostream(ios::binary) << | ostream() << | wostream() << | fopen("w,ccs=utf-8") wostream(FILE) << | fopen("w,ccs=utf-16le") wostream(FILE) codecvt_utf16 << |
- Windows API: n/a
- POSIX style: n/a
- C (unformatted and formatted):
setlocale(LC_ALL, ####)
- C++ (unformatted and formatted):
- binary, text (narrow input and output):
std::ostream::imbue(std::locale(####))
- wide, unicode (wide input, narrow output):
std::wostream::imbue(std::locale(####))
- wide unicode (wide input and output):
std::wostream::imbue(std::locale())
withstd::codecvt_utf16
- binary, text (narrow input and output):