如何在C++中使用%d,特别是在DrawText()中

How to use %d in C++, particularly in DrawText()

本文关键字:DrawText 特别是 C++      更新时间:2023-10-16

所以我听说过%d,但我不知道如何使用它。我想做的是:

DrawText (hdcWindow, "PLACE IN QUESTION" , -1, &rc, DT_SINGLELINE);

在"PLACE IN QUESTION"中,我想显示文本和一个变量,如"text%d"或者其他什么,但我不知道语法,我如何规定%d在显示时将代表什么?

DrawText不像printf或类似的东西那样工作。我建议您查看MSDN:MSDN:DrawText

int DrawText(
  _In_     HDC hDC,
  _Inout_  LPCTSTR lpchText,
  _In_     int nCount,
  _Inout_  LPRECT lpRect,
  _In_     UINT uFormat
);

你需要转换到LPCTSTR,你可以看看谷歌,如果我找到一个链接,我会把它给你,但它让我很久没有做C++了。

编辑:我发现:

int number = 1;
CString t;
t.Format(_T("Text: %d"), number);

然后CCD_ 1