我可以通过DrawText()绘制字符串文字
DrawText (hdcWindow, "abc123", -1, &rc, DT_SINGLELINE);然而,这不适用于其他任何情况。具体来说,我不能输出存储在变量中的值,比如int
int variable = 5;
DrawText (hdcWindow, variable, -1, &rc, DT_SINGLELINE);或者是一个char
char variable = a;
DrawText (hdcWindow, variable, -1, &rc, DT_SINGLELINE);如何使用DrawText()显示变量的内容?为什么使用像"abc123"这样的字符串字面值可以工作,而用variable替换它就不行?
发布于 2013-07-08 10:40:20
DrawText只知道如何显示字符串。要显示其他内容,您需要先转换为字符串,然后再显示该字符串。
void show_int(int x, /* ... */) {
std::stringstream buffer;
buffer << x;
DrawText(hdcWindow, buffer.str().c_str(), -1, &rc, DT_SINGLELINE);
}https://stackoverflow.com/questions/17518471
复制相似问题