• Popular Now

• 15
• 15
• 11
• 9
• 10

Archived

This topic is now archived and is closed to further replies.

Clearing text off Console

This topic is 5454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

simple question how 2 clear text off Console... Easy way of programming: Code, Graphics, Swearing....

windows.h

system("cls");

Share on other sites
what if only in a certain area?

Easy way of programming: Code, Graphics, Swearing....

[edited by - XDarkScar on April 17, 2003 10:28:03 PM]

Share on other sites
I''m not sure, but what I do is if there''s always something there (i.e. game board) I make a function and redraw it each time something changes.

Share on other sites
tx man

Easy way of programming: Code, Graphics, Swearing....

Share on other sites
quote:
Original post by nobodynews
I think I know what might work. First, you need a function that can set the cursor position based on x,y coordinates. These are usually compiler dependant. Let''s say the function is gotoxy(int x, int y) First say you have this as on your screen(the numbers are the window bounderies/coordinates):
+012345678900123  xxxxxx4  xxxxxx5  xxxxxx6    7    8     9
And you want to erase the x''s. This is how the function should look:

      void eraseScreenRect(int left, int top, int right, int bottom) {  for(int j = 0; j <= (top-bottom); j++) { // number of lines to erase    gotoxy(left, top+j); // go to start of box, then each new line    for(int i = 0; i <= (right - left); i++) { // number of spaces to print      cout << " ";    }  }  return;}
conio.h gotoxy:
To clear the x''s, you would call the function like this:
eraseScreenRect(2, 3, 7, 5);

http://www.jsquaredproductions.com/tutorials/ASCII_Attack_Ch1-2.html it may or may not work with vc++, I heard it doesn''t.

More on console functions: http://www.gametutorials.com/Tutorials/C/C_Pg3.htm

EDIT: various stuff. Oh, I haven''t tested this code, but hopefully it works and/or you get the jist.
EDIT2: Also, on the second link I gave, check out the section on "Introduction to Console Functions" and read over the source. The function that you want to use is SetConsoleCursorPosition

[edited by - nobodynews on April 17, 2003 11:14:44 PM]

gotoxy is only for borland compilers.

-~-The Cow of Darkness-~-