Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

C++ -> Drawing Rectangles to Console

2.63/5 (4 votes)
25 Aug 2011CPOL 17.3K  
Smaller code:void DrawRect(int x, int y, int width, int height, int curPosX=0, int curPosY=0){ setxy(x, y); cout << char(201); cout.width(width); cout.fill (char(205)); cout << char(187); setxy(x,height+y); cout << char(200); cout.width(width); cout.fill...
Smaller code:
void DrawRect(int x, int y, int width, int height, int curPosX=0, int curPosY=0)
{
    setxy(x,       y); cout << char(201); 
     cout.width(width); cout.fill (char(205)); cout << char(187);
    setxy(x,height+y); cout << char(200); 
     cout.width(width); cout.fill (char(205)); cout << char(188);
    for(int i = y + 1; i < height+y; i++)
    {
        setxy(x,i);cout << char(186);
        setxy(x + width,i);cout << char(186);
    }
    setxy(curPosX,curPosY);
}


Using ostream::width() and ostream::fill() functions.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)