是否可以使用Unicode“argv”?(Is it possible to use a Unicode “argv”?)

编程入门 行业动态 更新时间:2024-10-28 19:21:51
是否可以使用Unicode“argv”?(Is it possible to use a Unicode “argv”?)

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

包装需要使用Unicode,所以我使用wchar_t作为我拥有的字符和字符串。 现在我发现自己遇到了问题,我需要将程序的参数放在wchar_t和wchar_t字符串中。

可能吗? 我将main功能定义为

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

我应该使用wchar_t的argv吗?

非常感谢,我似乎没有找到有关如何在C中正确使用Unicode的有用信息。

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.

最满意答案

一般来说,没有。 它将取决于O / S,但是C标准认为'main()'的参数必须是'main(int argc,char ** argv)'或等价的,所以除非char和wchar_t是相同的基本类型,你不能这样做。

话虽如此,你可以在程序中获得UTF-8参数字符串,将它们转换为UTF-16或UTF-32,然后继续生活。

在Mac(10.5.8,Leopard)上,我得到了:

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

这都是UTF-8编码。 (odx是一个十六进制转储程序)。

另请参阅: 为什么在与UNIX / Linux环境进行交互时使用UTF-8编码

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

更多推荐

本文发布于:2023-07-19 17:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1184036.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   Unicode   argv

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!