我正在为使用文件作为参数的应用程序编写一个小包装器。
包装需要使用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
更多推荐
发布评论