1

我在显示由一些文本和一个整数组成的消息时遇到问题

这是我的代码:

int integerNumberOfImportantAppointments = calCalendar.getNumberOfImportantAppointments();

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

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

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

谢谢

4

3 回答 3

2

而不是使用sprintfor itoa(或类似的)你可能会更好std::istringstream

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。描述性的变量/函数名称很好,但也有这么长的名称。:)

于 2012-09-24T05:46:32.243 回答
0

关于这个:

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?");
}
于 2012-09-24T04:21:30.740 回答
0

尝试这个:

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?");
}
于 2012-09-24T04:40:58.297 回答