- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从同事那里得到了一段以前写的代码,令人困惑。代码是:
TCHAR Curr_dir[100];
char* input_file;
DWORD a = GetCurrentDirectory(100, Curr_dir);
size_t i= wcstombs(&input_file[i], Curr_dir, 100);
问题是 Curr_dir
不是 wcstombs
所需的类型。是否有其他函数可以对这种类型的变量执行 wcstombs
的操作?或者有什么办法可以转换吗?
最佳答案
看起来您的代码曾经支持多字节和 UNICODE,但在停止编译多字节后就退化了(不再支持 Windows 95)。
仅当您定义了 _UNICODE
时,这段代码才有意义。在这种情况下,它在预处理器之后结束如下:
wchar_t Curr_dir[100];
char* input_file;
unsigned long a = GetCurrentDirectoryW(100, Curr_dir);
size_t i= wcstombs(&input_file[i], Curr_dir, 100);
在本例中,GetCurrentDirectoryW
在 Curr_dir
中返回 UINCODE(宽字符串),并且出于某种原因将其转换为多字节字符串。并且字符的类型匹配。
但是,如果 _UNICODE
未定义,则代码将更改为以下内容:
char Curr_dir[100];
char* input_file;
unsigned long a = GetCurrentDirectoryA(100, Curr_dir);
size_t i= wcstombs(&input_file[i], Curr_dir, 100);
并且 GetCurrentDirectoryA
现在切换到 ANSI version of the API,不再调用 wcstombs
了。
通常,MDSN 文档在通用文本例程映射下有一个表格,其中包含所有版本的字符串函数(例如 strcmp-wcscmp-mbscmp
),wcstombs
没有“_t”版本,因此您可以需要使用#ifdef _UNICODE
。
但是,即使 Win32 API 的多字节版本可能仍受支持,继续使用它们也是没有意义的。
更多:https://www.codeproject.com/articles/76252/what-are-tchar-wchar-lpstr-lpwstr-lpctstr-etc
关于c - 将 GetCurrentDirectory 与 wcstombs 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47375398/
这段代码 int main (void) { int i; char pmbbuf[4]; wchar_t *pwchello = L"1234567890123456789012345
我有一个 utf-8 文件,我可以使用 widechar 函数正常处理它。 但是现在我需要以多字节形式转换和使用它们,而且我正在努力让它工作。 printf("%s\n",setlocale(LC_C
wcstombs documentation说,它“将宽字符代码序列转换为多字节字符串”。但它从来没有说什么是“宽字符”。 它是隐式的,比如将 utf-16 转换为 utf-8,还是转换是由某个环境变
WideCharToMultiByte() 和 wcstombs() 有什么区别什么时候用哪个? 最佳答案 简而言之:WideCharToMultiByte 函数在参数列表中公开了用于转换的编码/代码
我将我的系统升级到 fedora 33,之后我发现 stdlib.h 无法解析某些数据结构: In file included from /usr/include/c++/10/cstdlib:75,
如何将以下代码转换为使用 wcstombs_s 而不是 wcstombs? char dbcs[1024]; char *pbstr = (char *)pPropVar->bstrVal; int
我正在尝试将一些旧的 C/C++ 代码移植到 android(最新版本的 NDK),但我正在努力处理函数 wcstombs()。此函数在 Android 上返回奇怪的结果,我不知道为什么。 看看这段代
wcstombs 有三个参数。 WideCharToMultiByte 有八个参数, 如何替换? 如何使用wcstombs这样写: int kk = WideCharToMultiByte(936,
我无意中发现了一份我自己无法修复的 Valgrind 报告。我有一个从文件中读取 Microsoft“unicode”字符串(一系列以大小为前缀的两字节对齐的 wchar_t)的函数。示例文件可能如下
我从同事那里得到了一段以前写的代码,令人困惑。代码是: TCHAR Curr_dir[100]; char* input_file; DWORD a = GetCurrentDirectory(1
编译器 (VC 2010) 一直提示我使用它们。 如果不安全,请提供最简单的替换。 最佳答案 嗯,你有最常见的字符串函数的安全版本,它们以 _s 结尾,并提供了指定缓冲区长度的可能性。 关于C++/W
我正在努力将一些遗留的 C++ 代码移植到 Android 平台。这样做时,我注意到代码使用 iconv_xxx() 例程来处理 Unicode 转换。碰巧Android NDK默认没有iconv.h
我是一名优秀的程序员,十分优秀!