C++绘制矩形位置

C++ draw rectangle position

本文关键字:位置 绘制 C++      更新时间:2023-10-16

我有我的类:

class Rectangle : public TwoDim
{
public:
    void fun() {};
    void printShape();
    Rectangle(int x1, int y1, int height1, int width1)
    {
        x = x1;
        y = y1;
        height = height1;
        width = width1;
    }
};

以及打印它的功能:

void Rectangle::printShape()
{
    {
        cout << "+";
        for (int i = 0; i <  width - 2; i++)
        {
            cout << "-";
        }
        cout << "+n";
        for (int i = 0; i < height - 2; i++)
        {
            cout << "|";
            for (int j = 0; j < +width - 2; j++)
            {
                cout << " ";
            }
            cout << "|n";
        }
        cout << "+";
        for (int i = 0; i < width - 2; i++)
        {
            cout << "-";
        }
        cout << "+n";
    }
}

如何更改我的函数,以便从点(x, y)开始绘制矩形?

多谢

我会在实际打印之前输出y std::endl s,然后在有效打印每一行之前输出x " "