繁体   English   中英

Windows Concole中的希腊字母

[英]Greek letters in Windows Concole

我正在用C编写一个程序,当我在cmd.exe中运行它时,我希望在菜单中有希腊字符。 有人说为了包含希腊字符,你必须使用类似这样的printf

 printf(charset:IS0-1089:uffe);      

但他们不确定。

有谁知道这是怎么做到的吗?

假设Windows,您可以:

此代码打印γειά σου

#include "windows.h"

int main() {
  SetConsoleOutputCP(1253); //"ANSI" Greek
  printf("\xE3\xE5\xE9\xDC \xF3\xEF\xF5");
  return 0;
}

当编码为windows-1253时,十六进制代码表示γειά σου 如果使用将数据保存为windows-1253的编辑器,则可以使用文字。 另一种方法是使用OEM 737 (实际上是DOS编码)或使用Unicode。

我使用SetConsoleOutputCP来设置控制台代码页,但您可以在运行程序之前键入命令chcp 1253

一种方法是打印宽字符串。 不幸的是,Windows需要一些非标准的设置来使这项工作。 这段代码在#if块中进行了设置。

#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>

/* This has been reported not to autodetect correctly on tdm-gcc. */
#ifndef MS_STDLIB_BUGS // Allow overriding the autodetection.
#  if ( _WIN32 || _WIN64 )
#    define MS_STDLIB_BUGS 1
#  else
#    define MS_STDLIB_BUGS 0
#  endif
#endif

#if MS_STDLIB_BUGS
#  include <io.h>
#  include <fcntl.h>
#endif

void init_locale(void)
// Does magic so that wprintf() can work.
{
  // Constant for fwide().
  static const int wide_oriented = 1;

#if MS_STDLIB_BUGS
  // Windows needs a little non-standard magic.
  static const char locale_name[] = ".1200";
  _setmode( _fileno(stdout), _O_WTEXT );
#else
  // The correct locale name may vary by OS, e.g., "en_US.utf8".
  static const char locale_name[] = "";
#endif

  setlocale( LC_ALL, locale_name );
  fwide( stdout, wide_oriented );
}

int main(void)
{
  init_locale();
  wprintf(L"μουσάων Ἑλικωνιάδων ἀρχώμεθ᾽\n");
  return EXIT_SUCCESS;
}

这必须保存为带有BOM的UTF-8,以便旧版本的Visual Studio能够正确读取它。 您的控制台也必须设置为等宽的Unicode字体,例如Lucida Console,才能正确显示它。 为了将宽字符串与ASCII字符串混合,标准将%ls%lc格式说明符定义为printf() ,尽管我发现它们无处不在。

另一种方法是将控制台设置为UTF-8模式(在Windows上,使用chcp 65001执行此操作。)然后使用printf(u8"μουσάων Ἑλικωνιάδων ἀρχώμεθ᾽\\n");打印UTF-8字符串printf(u8"μουσάων Ἑλικωνιάδων ἀρχώμεθ᾽\\n"); UTF-8是Windows上的二等公民,但通常可以使用。 尽管如此,尝试在不设置代码页的情况下运行它,你会得到垃圾。

我认为这可能仅在您的控制台支持希腊语时才有效。 您可能想要做的是将字符映射到希腊语,但使用ASCII。 对于C#但在C中有相同的想法

913至936 =大写希腊字母

945至968 =小写希腊字母

阅读Suite101:使用希腊字母和C#:如何在创建C#应用程序时正确显示ASCII代码 Suite101.com在此链接

您可以使用printf打印unicode char字符,如下所示:

printf("\Ƞ\\n");

这将打印Ƞ

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM