[fpc-pascal] Unicode output on console works for me on Linux, not on Windows
Reinier Olislagers
reinierolislagers at gmail.com
Tue Aug 2 08:26:37 CEST 2011
On 1-8-2011 14:38, Ondrej wrote:
>> I think that you have to configure the console to use UTF-8 output (but I
>> don't know how this is done on Windows).
>
> I think that should be:
>
> SetConsoleOutputCP(CP_UTF8);
>
Thanks all, I got it to work using SetConsoleOutput.
UTF8ToConsole did not work for me.
For posterity/the archives:
program uniconsole;
{$mode objfpc}{$H+}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
{$IFDEF UseCThreads}
cthreads,
{$ENDIF}
{Widestring manager needed for widestring support}
cwstring,
{$ENDIF}
{$IFDEF WINDOWS}
Windows, {for setconsoleoutputcp}
{$ENDIF}
Classes
;
var
UTF8TestString: string;
begin
{$IFDEF WINDOWS}
SetConsoleOutputCP(CP_UTF8);
{$ENDIF}
UTF8TestString:= 'rosé, водка and ούζο';
writeln ('plain: ' + UTF8TestString);
{Apparently we don't need UTF8ToConsole for this
UTF8ToConsole did not do anything for me in fact.}
end.
More information about the fpc-pascal
mailing list