- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当我 #include <windows.h>
在 C 或 C++ 中,我被迫决定字符的格式,其中 TCHAR
要么等于 char
或 wchar_t
.
我四处看了很多,就像 this one 这样的帖子或类似 this 的网站指出 wchar_t
事情发生在 UTF8 之前的很久以前,并且由于各种原因,在现代编程中并不是一个特别好的 Unicode 解决方案。然而,这些并没有说明对已经在 wchar_t
中运行的现有系统的支持。 .
所以我的问题是,我应该使用哪一个?如果我使用普通的 char
这会在未来被 MS 放弃吗,因为在一天结束时,wchar_t
API 版本更新?或者如果我使用 wchar_t
, 让我的代码在其他现代平台上运行会很痛苦吗,这些平台后来使用普通的旧 char
开发在 UTF8 中?
最佳答案
它绝对有用,也是正确处理任意路径名的唯一方法(因为它们允许包含宽字符)。 UTF-16 的选择经常受到批评(有充分的理由),但这无关紧要。操作系统使用它,所以你也必须使用它。您可以做的最好的事情是始终调用 WINAPI 函数的宽字符版本(例如 OpenFileW
)并在您的程序内部使用 UTF-8。是的,这意味着来回转换,但这通常不是性能瓶颈。
我强烈推荐 UTF-8 Manifesto这解释了为什么客观上这是最好的方法。
Portability, cross-platform interoperability and simplicity are more important than interoperability with existing platform APIs. So, the best approach is to use UTF-8 narrow strings everywhere and convert them back and forth when using platform APIs that don’t support UTF-8 and accept wide strings (e.g. Windows API). Performance is seldom an issue of any relevance when dealing with string-accepting system APIs (e.g. UI code and file system APIs), and there is a great advantage to using the same encoding everywhere else in the application, so we see no sufficient reason to do otherwise.
关于c++ - wchar_t 对 Windows API 有用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37592975/
error C2440: 'initializing': cannot convert from 'TCHAR [260]' to 'std::basic_string,std::allocator>
首先。我想说,我不是 C++ 程序员。outlook 字符串在 visual studio 2015 中生成错误,并显示标题中的消息。 HWND windowHandle = (HWND)FindPr
我正在尝试检查一个 wchar_t * 是否等于另一个 wchar_t * 不区分大小写。有人可以把我放在正确的位置吗? 这是我尝试过的: wchar_t *vectored[80] = { ...
这是我的代码: wchar_t wbuffer[512]; wchar_t* wc = (wchar_t*) malloc(buffer_size); int buflen = 0;
如何正确转换这种方式? VARIANT varIndex; CString csIndex; //Index BSTR csIndex = (LPCSTR)(_bstr
我将以下代码作为我正在编写的字符串类中的私有(private)函数(它是从 wstring_convert “借来的”,并由我进行了一些修改): template std::string my_st
我有这样的东西: vector elements; 其中包含: 083938F8 083938FA 083938FC 083938FE 08393900 08393902 08393904 我想将它们
字符的签名不规范。因此,有signed char和unsigned char类型。因此,使用单个字符的函数必须使用既可以包含有符号字符又可以包含无符号字符的参数类型(此 类型选择为int),因为如果参
我在 Visual Studio C++ 2013 Community Edition 中遇到了一些奇怪的事情,这可能是编译器错误,也可能是我正在编写在没有警告的情况下进行编译的无效代码。 考虑以下片
我无法理解为什么某个隐式转换没有按我预期的那样工作。我有以下类(class) ref class ManagedWStringArrayWrapper { wchar_t** m_pointe
我有一个名为 DirToEmpty 的变量,它保存临时目录的路径。 我有另一个名为 TempBufDir 的变量,它将保持与 DirToEmpty 相同的值,但反斜杠被转义。 预期行为示例: wcha
我需要在附加 '\n' 后将多字节字符发送到套接字,但我拥有的是一个 const wchar_t*。我如何转换它? 最佳答案 如果您的问题是如何实际操作常量的内容,请考虑 const_cast . 关
我正在尝试使用语言环境方面将 wstring 转换为字符串,但我遇到了以下错误: test_facet.cpp: In function ‘int main()’: test_facet.cpp:14
我正在尝试使用 C++ 更改文件的属性我究竟做错了什么 ?代码完全拿下 https://learn.microsoft.com/en-us/windows/win32/stg/writeread-sa
我尝试将以下字符串数组传递给函数: const wchar_t *testTokens[] = { L"function", L"(",
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我尝试将阿拉伯字符存储为 wchar_t,然后将其打印到控制台,但无法使其工作。 我已将控制台设置为 UTF-8,如果我只是将阿拉伯字母输入控制台,它们就会正确显示(尽管未加入)。 我根据( How
我想存储一个包含扩展 ascii 表中字符的字符串,并打印它们。我尝试过: wchar_t wp[] = L"Росси́йская Акаде́мия Нау́к "; printf("%S", w
在C++ Visual Studio 2017中使用main函数是否错误如下: int main(int argc, wchar_t* argv[]) 因为我的程序可以接收特殊字符。 最佳答案 请阅读
我有这个运算符重载器。我的程序在创建新的 wchar_t 数组时崩溃。 myObject &operator += (const myObject &s) { wchar_t *cat = w
我是一名优秀的程序员,十分优秀!