是否有可能使用一个统一code" argv的"? [英] Is it possible to use a Unicode "argv"?

查看:114
本文介绍了是否有可能使用一个统一code" argv的"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个小包装为使用文件作为参数的应用程序。

包装器需要在统一code,所以我使用的wchar_t的字符和字符串我有。现在我发现自己在一个问题,我需要有程序的参数中的wchar_t的的阵列和在wchar_t字符串。

这可能吗?我定义了功能

  INT主(INT ARGC,CHAR *的argv [])

我应该使用wchar_t的对的argv

非常感谢你,我似乎无法找到如何在C正确使用统一code有用的信息。


解决方案

在一般情况下,没有。这将取决于O / S,但C标准说')主('的参数必须是'主(INT ARGC,字符** argv的)'或等价的,所以除非char和wchar_t的是相同的基本型,你不能做到这一点。

说了这么多,你可以得到UTF-8的参数字符串进入程序,将它们转换为UTF-16或UTF-32,然后享受生活。

在Mac(10.5.8,豹),我得到了:

 奥西里斯JL:回声我€| ODX
0×0000:C3 AF E2 82 AC 0A ......
0x0006:
奥西里斯JL:

这是所有UTF-8 EN codeD。 (ODX是一个十六进制转储程序)。

另请参阅:为什么在UNIX / Linux环境

I'm writing a little wrapper for an application that uses files as arguments.

The wrapper needs to be in Unicode, so I'm using wchar_t for the characters and strings I have. Now I find myself in a problem, I need to have the arguments of the program in a array of wchar_t's and in a wchar_t string.

Is it possible? I'm defining the main function as

int main(int argc, char *argv[])

Should I use wchar_t's for argv?

Thank you very much, I seem not to find useful info on how to use Unicode properly in C.

解决方案

In general, no. It will depend on the O/S, but the C standard says that the arguments to 'main()' must be 'main(int argc, char **argv)' or equivalent, so unless char and wchar_t are the same basic type, you can't do it.

Having said that, you could get UTF-8 argument strings into the program, convert them to UTF-16 or UTF-32, and then get on with life.

On a Mac (10.5.8, Leopard), I got:

Osiris JL: echo "ï€" | odx
0x0000: C3 AF E2 82 AC 0A                                 ......
0x0006:
Osiris JL:

That's all UTF-8 encoded. (odx is a hex dump program).

See also: Why is it that UTF-8 encoding is used when interacting with a UNIX/Linux environment

这篇关于是否有可能使用一个统一code" argv的"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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