我不断收到此错误消息:
状态错误C2664-int MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT)':无法将参数2从'const char *'转换为'LPCWSTR'“ 31
这是我的下面的代码。我知道这与通过what()
错误类中的函数传递const类型有关。由于某种原因,它是不兼容的。有任何想法吗?
// 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;
std::runtime_error::what()
返回const char*
,因此您应该使用MessageBoxA()
,而MessageBox()
不是MessageBoxW()
。
MessageBoxA(nullptr, error.what(), "An error has occured", MB_OK);
同样不要忘记L
从字符串文字中删除前缀。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句