【问题标题】:How to draw DrawString with an int variable如何使用 int 变量绘制 DrawString
【发布时间】:2017-08-31 21:24:53
【问题描述】:

所以我正在使用 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 *);

【问题讨论】:

    标签: c++ gdi+


    【解决方案1】:

    以下应该可以工作(包括<sstream> 标头):

    //...
    for (size_t i = 0; i < n; ++i)
    {
        std::string printStr;
        {
            std::stringstream sstr;
            sstr << i;
            printStr = sstr.str();
        }
        //now, you can use printStr
        //...
    }
    

    【讨论】:

    • 感谢您的建议,它仍然不起作用。在 graphics.DrawString ... 期间我仍然得到一条红色的波浪线...
    • 很抱歉,但这听起来不像是在不查看更多代码的情况下有人可以解决的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    • 1970-01-01
    相关资源
    最近更新 更多