【问题标题】:ShowMessage with text and integer components带有文本和整数组件的 ShowMessage
【发布时间】:2012-09-24 04:14:23
【问题描述】:

我无法显示由某些文本和整数组合而成的消息

这是我的代码:

int integerNumberOfImportantAppointments = calCalendar.getNumberOfImportantAppointments();

if (integerNumberOfImportantAppointments > 0)
{
    ShowMessage("You have " + integerNumberOfImportantAppointments + " important appointments. Do you wish to view them?");
}

我收到以下错误:E2085 无效的指针添加

我可以帮我解决这个问题吗?

谢谢

【问题讨论】:

    标签: c++ string integer message


    【解决方案1】:

    您最好使用std::istringstream,而不是使用sprintfitoa(或类似的):

    int iNumberOfImportantAppointments = calCalendar.getNumberOfImportantAppointments();
    
    if (iNumberOfImportantAppointments > 0)
    {
        std::istringstream istr;
        istr << "You have " << iNumberOfImportantAppointments << " important appointments. Do you wish to view them?";
        ShowMessage(istr.str().c_str());
    }
    

    PS。描述性的变量/函数名称很好,但也有这样的太长名称。 :)

    【讨论】:

      【解决方案2】:

      试试这个:

      int integerNumberOfImportantAppointments = calCalendar.getNumberOfImportantAppointments();
      if (integerNumberOfImportantAppointments > 0)
      {
         // itoa is not standard (like any of this is)
         WCHAR strN[32];
         swprintf(strN, L"%d", integerNumberOfImportantAppointments);
      
         // not familiar with ShowMessage(), but I *think* this will work.
         ShowMessage("You have " + UnicodeString(strN) + " important appointments. Do you wish to view them?");
      }
      

      【讨论】:

        【解决方案3】:

        关于这个:

        int integerNumberOfImportantAppointments = calCalendar.getNumberOfImportantAppointments();
        char buffer[30];
        if (integerNumberOfImportantAppointments > 0)
        {
        itoa (integerNumberOfImportantAppointments,buffer,10);
            ShowMessage("You have " + buffer + " important appointments. Do you wish to view them?");
        }
        

        【讨论】:

        • 谢谢。我收到以下错误:E2193 Too little parameters in call to 'itoa(int,char *,int)' and E2034 Cannot convert 'string' to 'UnicodeString'
        猜你喜欢
        • 2013-12-04
        • 2015-08-19
        • 1970-01-01
        • 2015-04-08
        • 2018-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-15
        相关资源
        最近更新 更多