C++ 错误:由于 swprintf 而从 'int' 到 'const wchar_t* 的转换无效
C++ error:invalid conversion from 'int' to 'const wchar_t* because of swprintf
我要编译的文件
第一个错误:
无法将"wchar_t*"转换为"LPCSTR" {又名"const char*"}|
我通过将WriteConsoleOutputCharacter
更改为WriteConsoleOutputCharacterW
来修复它。
但是,我在此行上收到另一个错误:
swprintf(screen, 40, L"X=%3.2f, Y=%3.2f, A=%3.2f FPS=%3.2f ", fPlayerX, fPlayerY, fPlayerA, 1.0f/fElapsedTime);
从"int"到"const wchar_t*"的转换无效 [-允许]| 初始化 'int swprintf(wchar_t*, const wchar_t*, ...(' 的参数 2
|
如何编译此代码?
您使用的swprintf
函数似乎没有缓冲区大小。您可能需要考虑改用_snwprintf
。
_snwprintf(screen, 40, L"X=%3.2f, Y=%3.2f, A=%3.2f FPS=%3.2f ", fPlayerX, fPlayerY, fPlayerA, 1.0f/fElapsedTime);
您可能会收到此函数不安全的警告 - 建议的替代方法是_snwprintf_s
,您必须指定缓冲区的大小和要写入的最大字符数。在实践中,这些通常是相同的,因此大多数时候,对此函数的调用如下所示:
_snwprintf_s(screen, 40, 40, L"X=%3.2f, Y=%3.2f, A=%3.2f FPS=%3.2f ", fPlayerX, fPlayerY, fPlayerA, 1.0f/fElapsedTime);
相关文章:
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 无法访问嵌套类.类的使用无效
- MacOS通过在莫哈韦"wchar.h"下破碎的自制啤酒发出叮当声
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- FFMPEG配置文件级别id大小无效
- 错误:从"int"到枚举c++的转换无效
- 如何修复此错误:className::className的无效使用
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- C++-模板嵌套类的引用初始化无效
- 错误:无效的预处理指令 #i 的意思是 #if?
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- 从 'int' 到 'int*' CPP 的转换无效
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- C++ PTHREADS - 无效转换无效*(*)()到无效*(*)(无效*)
- 声明为无效的变量或字段'...' Ardunio 编译器上的错误
- 数组下标的类型"float*[float]"无效