无法使用 swprintf 在 WCHAR* 中打印字符*
Can't print char* in WCHAR* with swprintf
我有那个有效的函数(我只需要在最后将 wstring 转到 WHAR*(:
wstring stringtowstring(string str)
{
WCHAR ch[256];
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, (LPWSTR)ch, 256);
return wstring(ch);
}
但我想知道为什么没有:
WCHAR tmp[256];
swprintf(tmp, L"%s", "test");
假设Visual Studio在上下文中,这是swprintf
记录的非标准行为。
使用 c 和 s指定的字符和字符串参数由printf 系列函数解释为 char 和 char*,或由 wprintf 系列函数解释为wchar_t 和 wchar_t*。使用 C 和 S 指定的字符和字符串参数由 printf 系列函数解释为 wchar_t 和 wchar_t*,或由 wprintf 系列函数解释为 char 和 char*。此行为特定于Microsoft。
Microsoft特异性: Z 类型字符以及 c、C、s 和 S 类型字符与 printf 和 wprintf 函数一起使用时的行为是Microsoft 扩展。ISO C 标准在所有格式化函数中一致地对窄字符和字符串使用 c 和 s,对宽字符和字符串使用 C 和 S。
相关文章:
- 打印字符数组地址的正确方法
- c ++控制台应用程序,如何在控制台外部打印字符
- 无法使用 swprintf 在 WCHAR* 中打印字符*
- 存储和打印字符,但输出不是预期的
- 如何使 printf 以与 NSLog 相同的方式打印字符缓冲区?
- 在带有 (void*) 强制转换的字符串中打印字符的内存地址
- C++无法打印字符变量
- 无法打印字符向量C++向量
- 为什么在编辑 fastq 文件并将输出写入新的 fastq 文件时引入不可打印字符?
- C :如何询问文件名并打印字符数组
- 循环中的 Cout 不会按定义的字符逐个打印字符
- (C++) 打印字符数组字符串的单词时出现问题
- 用putchar在屏幕上打印字符
- 在C 中使用继续语句的打印字符
- 在 for 循环 c++ 中打印字符
- 使用while和if递归打印字符
- 打印字符数组 c++
- 如何使用Xcode中的Unicode打印字符╔(和其他字符)
- cout.put() 是否推荐使用 cout<< 打印字符
- C++ 中的密码 |打印字符后删除字符