Click here to Skip to main content
13,145,774 members (62,866 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

8.7K views
1 bookmarked
Posted 25 Aug 2011

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) Freelancer
Spain Spain
No Biography provided

You may also be interested in...

Comments and Discussions

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

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

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

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