本文介绍了我应该从Windows代码中消除TCHAR吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改一些非常旧的(10年)C代码.该代码在带有GCC的Unix/Mac上编译,并在Windows上与MinGW的交叉编译中.目前,整个过程中都有TCHAR字符串.我想摆脱TCHAR,而改用C ++字符串.还是有必要使用Windows范围的功能,还是我现在可以使用Unicode和UTF-8进行所有操作?

I am revising some very old (10 years) C code. The code compiles on Unix/Mac with GCC and cross-compiles for Windows with MinGW. Currently there are TCHAR strings throughout. I'd like to get rid of the TCHAR and use a C++ string instead. Is it still necessary to use the Windows wide functions, or can I do everything now with Unicode and UTF-8?

推荐答案

Windows仍然使用UTF16,并且很可能始终使用UTF16.因此,您需要使用wstring而不是string. Windows API不直接提供对UTF8的支持,主要是因为Windows在发明UTF8之前就支持Unicode.

Windows uses UTF16 still and most likely always will. You need to use wstring rather than string therefore. Windows APIs don't offer support for UTF8 directly largely because Windows supported Unicode before UTF8 was invented.

因此,编写可在Windows和Unix平台上编译的Unicode代码会非常痛苦.

It is thus rather painful to write Unicode code that will compile on both Windows and Unix platforms.

这篇关于我应该从Windows代码中消除TCHAR吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:00