在这里,我分配Cstring.Format。有什么办法可以转换吗?使用它时,出现以下错误

void Cchart_event_07Dlg::OnMouseDownClientserver1(LPDISPATCH sender, LPDISPATCH args)
{
    /*This Event will display a MessageBox with the series and point information, as well as the XY coordinates.
    This is done when clicking anywhere in the Chart control. */

    Cfx62::_MouseEventArgsXPtr myArgs = (Cfx62::_MouseEventArgsXPtr)args;

    int x = myArgs->X;
    int y = myArgs->Y;
    int pointVal = myArgs->Point + 1;
    int series = myArgs->Series + 1;

    CString strTemp;

    enum Cfx62::HitType _result;
    HRESULT _hr = myArgs->get_HitType(&_result);

    if (_result == Cfx62::HitType_Point)
    {
        strTemp.Format("Series: %d, Point: %d, X: %d, Y: %d", series, pointVal, x, y);
        MessageBox(strTemp, NULL, MB_OK);
    }

    UpdateData(true);
}

最佳答案

只需在字符串常量之前添加L即可将其标记为宽字符串:

strTemp.Format(L"Series: %d, Point: %d, X: %d, Y: %d", series, pointVal, x, y);

关于c++ - 无法将参数1从 'const char *'转换为 'const wchar_t *',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39693959/

10-15 15:06