带有文本和整数组件的 ShowMessage

Posted

技术标签:

【中文标题】带有文本和整数组件的 ShowMessage【英文标题】:ShowMessage with text and integer components 【发布时间】: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 无效的指针添加

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

谢谢

【问题讨论】:

【参考方案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'

以上是关于带有文本和整数组件的 ShowMessage的主要内容,如果未能解决你的问题,请参考以下文章