获取Dev-C ++构建的程序以将UNICODE字符输出到Windows命令行 [英] Getting a Dev-C++ built program to output UNICODE characters to the Windows command line

查看:403
本文介绍了获取Dev-C ++构建的程序以将UNICODE字符输出到Windows命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您能回答我的任何问题,那将很棒。

If you can answer any of my questions, that would be awesome.

这里是独家新闻:我正在向11年级的学生讲授编程课程入门。 。到目前为止,一切都很顺利,他们的英语水平足够高,我可以用英语教书,让他们用英语编写程序,而且一切都很好。

Here's the scoop: I'm teaching an intro to programming class in Thailand to 11th graders. It's been going great so far, their level of English is high enough that I can teach in English and have them write programs in English and everything is fine and dandy.

但是作为使用非拉丁字符的语言的使用者,我认为他们至少应该学习什么是UNICODE。我不会在上面测试它们,也不会详细介绍实现细节,但我想向他们展示一个可以使用泰语字符进行I / O的UNICODE程序的示例。

However, as speakers of a language with non-Latin characters, I feel that they should at least learn what UNICODE is. I won't test them on it or bog them down with implementation details, but I want to show them an example of a UNICODE program that can do I/O with Thai characters.

我在以下约束下进行操作,这些约束都不能更改(至少在本学期中):

I'm operating under the following constraints, none of which can be changed (at least for this semester):


  • 程序必须在Windows 7上运行

  • 程序必须使用C语言(不是C ++)

  • 我们必须使用Dev-C ++(版本4.9.9.3)作为我们的IDE(我将尝试说服管理员在下学期进行更改,但他们可能不想这样做)

  • 程序应输出到命令行(我想希望它看起来像我们到目前为止一直在写的程序)

  • 我希望它易于设置和运行,尽管我不反对包含Batch文件来为孩子们做一些设置工作。

  • The program must run on Windows 7
  • The program must be in C (not C++)
  • We must use Dev-C++ (v. 4.9.9.3) as our IDE (I'm going to try and convince the admins to change for next semester, but they may not want to)
  • The program should output to the Command Line (I'd like it to "look like" the programs we've been writing so far)
  • I want it to be easy to set up and run, though I'm not opposed to including a Batch file to do some setup work for the kids.

这是我走了多远,还有一些问题:

Here's how far I've gotten, and the questions I have:


  • 在控制面板>区域>管理>非联合国语言ICODE程序设置为泰语。

  • 我使用 chcp 874设置了泰语代码页,但是来自键盘的字符却显示为垃圾字符。

  • 我用以下代码写了一个程序:printf( \u0E01\n);这可能是因为键盘映射错误还是必须更改其他内容?打印print,泰语字母表中的第一个字母。这是正确的语法吗?

  • 我收到一个编译器警告,仅C ++和C99支持通用字符。 Dev-C ++不能编译为C99吗?有没有办法为我提供C99编译器?

  • 我运行了代码并得到了垃圾字符。我想这可能是由于编译器,命令行或其他许多原因造成的。

  • In Control Panel > Regions > Administrative > Language for non-UNICODE programs is set to Thai.
  • I used "chcp 874" to set the Thai codepage in the Command Line, but characters from the keyboard come appear as garbage characters. Is this maybe because the keyboard mappings are wrong or do I have to change something else?
  • I wrote a program with the line: printf("\u0E01\n"); which prints ก, the first letter in the Thai alphabet. Is that the right syntax?
  • I received a compiler warning that "Universal Characters are only supported in C++ and C99." Does Dev-C++ not compile to C99? Is there a way I could get a C99 compiler for it?
  • I ran the code and got garbage characters. I imagine this could be because of the compiler, the command line, or any number of other things.

我很想结束本课程的程序输出outputs,泰语相当于 Hello World!我已经进行了大量的谷歌搜索,但是我发现的每个答案在这种情况下都不起作用,或者涉及不同的IDE。

I'd love to end this course with a program that outputs สวัสดีโลก, the Thai equivalent of "Hello World!" I've done tons of googling, but every answer I've found either doesn't work in this specific case or involved a different IDE.

推荐答案

好的,这是我的帮助。我不使用Dev-C ++作为我的IDE,所以我无法帮助您解决IDE特定的问题,但是以下是大多数C / C ++编译器的标准配置:

Ok, here's my bit of help. I don't use Dev-C++ as my IDE, so I can't help you with IDE specific things, but the following is standard to most C/C++ compilers:

wprintf 是宽字符(unicode)的 printf 实现。

wprintf is the printf implementation for wide characters (unicode).

使用宽字符时,将使用 wchar_t 代替 char 来定义字符串。

When using wide characters you will use wchar_t in place of char for defining strings.

所以您可能会做类似的事情

so you might do something like this

#include <wchar.h>

int main(int argc, char** argv) {
    wchar_t* str = L"สวัสดีโลก";
    wprintf(L"%s", str);
    system("pause");
    return 0;
}

wprintf 最多

其他用于打印和操作宽字符串的函数可以通过研究 wchar.h 头文件。

Other functions for printing and manipulating wide strings can be found by researching the wchar.h header file.

参考:
wprintf-C ++参考

在引号前使用L表示您打算定义一个宽字符串。 (unicode)

Using L before the quotations means you intend to define a wide string. (unicode)

希望有帮助,

-戴夫

这篇关于获取Dev-C ++构建的程序以将UNICODE字符输出到Windows命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆