所以我正在使用 Gdiplus 并尝试使用 Drawstring 方法输出一些文本。
我有
graphics.DrawString(&myVariable, -1, &myFont, Gdiplus::PointF(x, y), &brushVariable);
但是对于 &myVariable 参数,我想从我的 for 循环中打印出整数。因为它是一个整数,我需要把它变成一个字符串。我研究了如何使用 stringstream 和 to_string(i) 执行此操作,但是 DrawString 方法仍然给我一个错误,说我没有输入正确的参数。我知道这是 &myVariable 参数的问题,因为我不确定如何将 int 转换为可以使用 & 取消引用的字符串。 论点是: DrawString(std::string *, int, Gdiplus::font *, Gdiplus::PointF, Gdiplus::SolidBrush *);
最佳答案
以下应该有效(包括 <sstream>
header ):
//...
for (size_t i = 0; i < n; ++i)
{
std::string printStr;
{
std::stringstream sstr;
sstr << i;
printStr = sstr.str();
}
//now, you can use printStr
//...
}
关于c++ - 如何使用 int 变量绘制 DrawString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43245154/