C++ 错误C2664:MessageBoxW无法将参数2从';常量字符';至';LPCWSTR';

C++ 错误C2664:MessageBoxW无法将参数2从';常量字符';至';LPCWSTR';,c++,window,C++,Window,我一直收到以下错误消息: 状态错误C2664--int MessageBoxW(HWND、LPCWSTR、LPCWSTR、UINT)':无法将参数2从'const char*'转换为'LPCWSTR'”31 这是我下面的代码。我知道它与通过error类中的what()函数传递常量类型有关。出于某种原因,它不兼容。有什么想法吗 // on startup execute to determine exceptions try { // instantiate object app of c

我一直收到以下错误消息:

状态错误C2664--int MessageBoxW(HWND、LPCWSTR、LPCWSTR、UINT)':无法将参数2从'const char*'转换为'LPCWSTR'”31

这是我下面的代码。我知道它与通过error类中的
what()
函数传递常量类型有关。出于某种原因,它不兼容。有什么想法吗

// on startup execute to determine exceptions
try
{
    // instantiate object app of class AppWindow
    AppWindow app;

    // if(initialize function in class app is executed, and while the app is running, broadcast app)
    if (app.init())
    {
        while (app.isRun())
        {
            app.broadcast();
        }
    }
}

// if the following error is found, execute MessageBox function with following parameters
catch (const std::runtime_error& error)
{
    // parameters(has no owner window so displays independently)
    MessageBox(nullptr,  error.what(), L"An error has occured", MB_OK);
}

return 0;
返回
const char*
,因此您应该使用
MessageBoxA()
,而不是
MessageBox()
MessageBoxW()

MessageBoxA(nullptr,error.what(),“发生错误”,MB_OK);
另外,不要忘记从字符串文本中删除
L
前缀。

返回
const char*
,因此应该使用
MessageBoxA()
,而不是
MessageBox()
MessageBoxW()

MessageBoxA(nullptr,error.what(),“发生错误”,MB_OK);

也不要忘记从字符串文本中删除
L
前缀。

您可以使用
MessageBoxA()
并从标题字符串中删除
L
前缀。或者将
e.what()
转换为
wchar\u t
字符串。

您可以使用
MessageBoxA()
并从标题字符串中删除
L
前缀。或者转换
e.what()
指向
wchar\u t
字符串。

一个
LPCWSTR
是指向
wchar\u t
元素数组的指针,每个元素都是16位而不是8位字符,并且,举个例子,许多重复项中的两个,是通过将错误消息粘贴到此站点的搜索字段中获得的。当消息包含窄字符s时trings,hard use MessageBoxA.
LPCWSTR
是一个指向
wchar\u t
元素数组的指针,每个元素都是16位而不是8位字符,并且,仅举其中的两个,通过将错误消息粘贴到此站点上的搜索字段中获得。当messageboxing窄字符串时,hard useMessageBoxA。