TCHAR 仍然相关吗?

时间:2022-10-16
本文介绍了TCHAR 仍然相关吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我是 Windows 编程的新手,在阅读了 Petzold 的书后,我想知道:

I'm new to Windows programming and after reading the Petzold book I wonder:

使用 TCHAR 类型和 _T() 函数来声明字符串还是我应该只使用 wchar_t 函数的好习惯> 和 L"" 字符串在新代码中?

is it still good practice to use the TCHAR type and the _T() function to declare strings or if I should just use the wchar_t and L"" strings in new code?

我将只针对 Windows 2000 及更高版本,并且我的代码从一开始就是 i18n.

I will target only Windows 2000 and up and my code will be i18n from the start up.

推荐答案

如果我今天在做一个新项目,我仍然会使用 TCHAR 语法.使用它和 WCHAR 语法之间没有太大的实际区别,我更喜欢明确字符类型的代码.由于大多数 API 函数和辅助对象采用/使用 TCHAR 类型(例如:CString),因此使用它才有意义.此外,如果您决定在某个时候在 ASCII 应用程序中使用代码,或者如果 Windows 演变为 Unicode32 等,它会为您提供灵活性.

I would still use the TCHAR syntax if I was doing a new project today. There's not much practical difference between using it and the WCHAR syntax, and I prefer code which is explicit in what the character type is. Since most API functions and helper objects take/use TCHAR types (e.g.: CString), it just makes sense to use it. Plus it gives you flexibility if you decide to use the code in an ASCII app at some point, or if Windows ever evolves to Unicode32, etc.

如果你决定走 WCHAR 路线,我会明确说明这一点.即,使用 CStringW 代替 CString,并在转换为 TCHAR 时转换宏(例如:CW2CT).

If you decide to go the WCHAR route, I would be explicit about it. That is, use CStringW instead of CString, and casting macros when converting to TCHAR (eg: CW2CT).

无论如何,这就是我的看法.

That's my opinion, anyway.

这篇关于TCHAR 仍然相关吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一条:C99 stdint.h 头文件和 MS Visual Studio 下一条:ios_base::sync_with_stdio(false) 的意义;cin.tie(NULL);

相关文章

最新文章