Help related to System("cls")

Hi.

I'm back again,
I want to make my program less dependant on windows,
thus changing every windows based command line.

Which means, I need something to replace the *System("cls")* command with,
all help is much appreciated.

Thanks in advance,
-Rev
One way to do it is to use ANSI escapes. Windows, DOS, and most Unices should all support the ANSI escape codes. See

http://en.wikipedia.org/wiki/ANSI_escape_code

1
2
char cls[] = { 0x1b, '[', '2', 'J', 0 };
cout << cls;
Hmm, something seems off.
It doesn't clear the screen, it just makes an arrow in the start of every line from that point on :\
Bumping, have read around quite a bit today and I can't seem to find out what's wrong.
So I'm still in need of help :\
closed account (z05DSL3A)
JSmiths code does not work on a windows default command shell configuration.

You would need to load the command.com shell interpreter with the ansi.sys driver.

Last edited on
Any idea what I need to include for that?
closed account (z05DSL3A)
Try:
http://www.windowsnetworking.com/kbase/WindowsTips/Windows2000/UserTips/Miscellaneous/CommandInterpreterAnsiSupport.html
The closest, and most reliable, way of doing it is to simply print a bunch of \n characters to the screen. It clears the screen, but the cursor is still at the bottom, unfortunately. To get it back to the top, you would need to use something like SetConsoleCursorPosition() from the Windows API or something like setxy() or gotoxy() (I forget which one) from a CONIO library on Windows. On things like Linux, Unix, etc., you can use the ANSI escape code.

Note that there is a way to use ANSI escape codes on Windows and DOS, but a device driver is not loaded by default - ANSI.SYS. You would add the following to CONFIG.SYS on DOS-based versions of Windows:
DEVICE=C:\WINDOWS\SYSTEM32\ANSI.SYS

On Windows NT-based machines (NT, 2000, XP...), you add the following to CONFIG.NT:
DEVICE=%SystemRoot%\system32\ANSI.SYS

Edit - beat to the punch by the ever-present Grey Wolf. :P
Last edited on
Topic archived. No new replies allowed.