Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Go to top

C++ -> Drawing Rectangles to Console

, 25 Aug 2011
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Jose David Pujo
Software Developer (Senior) Prosoft
Spain Spain
No Biography provided

Comments and Discussions

 
QuestionMy vote of 4 PinprofessionalManikandan106-Jun-14 20:56 
GeneralRe: You don't need &lt;tchar.h&gt; for this one :)</tchar.h> PinmemberCaner Korkmaz31-Aug-11 21:18 
GeneralHello, The code is giving errors for cstduio and cstdlib fli... Pinmemberyogesh4ever29-Aug-11 19:39 
GeneralRe: I am using the following includes in stdafx.cpp (Visual Stud... PinmemberJose David Pujo29-Aug-11 20:13 
GeneralIt's a good way :) PinmemberCaner Korkmaz25-Aug-11 0:51 
GeneralRe: Thanks! PinmemberJose David Pujo25-Aug-11 2:08 
GeneralI'm trying it now :) PinmemberCaner Korkmaz25-Aug-11 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 25 Aug 2011
Article Copyright 2011 by Jose David Pujo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid