Use*_*123 1 c++ windows visual-studio
我是 Windows 上的 C/C++ 编码新手,在运行代码时遇到此错误。之前有人问过类似的问题,我将在下面链接,但是,这个解决方案对我不起作用,因为我没有更改字符集的选项。
const char* 类型的参数与“LPCWSTR”类型的参数不兼容
这是我的代码的样子。
#include <Windows.h>
INT CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpCmdLine, INT nCmdShow)
{
OutputDebugString("Lets test this out \n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有两种方法可以解决这个问题。
首先是使用由宽字符组成的字符串:
OutputDebugString(L"Lets test this out \n");
// ^
Run Code Online (Sandbox Code Playgroud)
其次是调用采用窄字符串的函数版本:
OutputDebugStringA("Lets test this out \n");
// ^
Run Code Online (Sandbox Code Playgroud)
由于 Windows API 更喜欢使用宽字符串,因此我更喜欢第一个解决方案。
PS LPCWSTR代表“指向恒定宽字符串的长指针”。已L过时,您可以忽略它。
| 归档时间: |
|
| 查看次数: |
4509 次 |
| 最近记录: |