我每次都必须使用_T()吗? Windows C ++ VS. [英] Do I have to use _T() every time? Windows C++ VS

查看:115
本文介绍了我每次都必须使用_T()吗? Windows C ++ VS.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次使用_T(text)宏都非常烦人。有没有办法只使用文字?或者为什么我不能?



仅在Visual Studio中出现此问题。例如,CodeBlocks没有问题(有时它会抛出警告)。



我尝试过的事情:



搜索msdn,看看为什么有必要,我注意到每个windows文本类型只是char *或const char *。所以我现在根本不理解_T()的想法。

Using _T("text") macro every single time is really annoying. Is there any way to use just "text"? Or why I can't?

This problem occurs in Visual Studio only. There is no problem in CodeBlocks for example (sometimes it just throws warning).

What I have tried:

Searching msdn to see why is it necessary, and I noticed that every windows text type is just char* or const char*. So I don't understand _T() idea at all now.

推荐答案

正如Sergey所说, _T()宏用于使您的代码源对UNICODE和ANSI构建都有好处。



如果您不需要UNICODE,那么您可以使用类似C的字符串文字(例如foo)。如果您只需要UNICODE,那么您可以使用,如Richard宽字符串文字(例如Lfoo)所示。



您也可以编写应用程序执行,作为预构建步骤,在源文件中更改foo - > _T(foo)所有字符串文字...
As noted by Sergey, the _T() macro is used to make your code source good for both UNICODE and ANSI builds.

If you don't need UNICODE then you could use C-like string literals (e.g. "foo"). If you need only UNICODE then you could use, as suggested by Richard wide-string literals (e.g. L"foo").

You could also write an application performing, as a pre-build step, on your source file the change "foo"->_T("foo") an all string literals...


如果要生成Unicode字符串然后是的你应该使用它。您可以使用 L 前缀,但这会阻止您生成程序的ASCII版本。是的,这有点痛苦,但编译器需要被指示生成正确的字符串版本,因为您的程序可能使用这两种类型。
If you want to generate Unicode strings then yes you should use it. You can just use the L prefix, but that prevents you from generating an ASCII version of your program. Yes it is a bit of a pain, but the compiler needs to be directed to generate the correct version of the string, since your program may use both types.


这篇关于我每次都必须使用_T()吗? Windows C ++ VS.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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