What is the quickest/most efficient way to clear console screen?

Hello world!

It's great to join a big forum like this but anyways cutting to the chase, I want your advice on what to use to clear the console screen. This could be just printing a thousand newlines because my console is static and un-scrollable (thanks to winapi).

I heard system("cls") isn't that encouraged and that is what I have been using so far!

I would also appreciate extra info like certain functions triggering anti-malware because that's not something I want if I want to be sharing these programs with my friends and family.

Thanks for reading and cheers! :D
Which of them to use? (I use Windows)
Last edited on
See the "Windows API" way in the page Repeater linked.
system cls should not trigger normal antivirus software. Cls is a perfectly legal console command. system is a perfectly legal tool provided in C++ to invoke external programs. There are better tools to invoke external programs, but its fine. System calls carry a slight risk; a very, very bored hacker could get into your friend's machine, discover your program, disassemble it to see how it works, find the system call, inject a new cls.exe or cls.bat into the folder where the program runs, and cause your program to run their malware program. The odds of this happening on your buddies computer are about like winning the lottery. No hacker is that bored, unless your friend is a VIP and targeted by hackers.
Use system cls if you want to, unless you are writing professional code that you plan to sell. In which case, you would be doing something really unusual to be selling console programs (they exist but are mostly found as bonus utilities as part of a larger package for doing administration type tasks).

that said, system is the easy way to do it in code. the win API probably clears it a little faster as the system call pokes the operating system, runs an external program, and does some other stuff that is technically slow but in the grand scheme of things fast enough. Its probably a full order of magnitude slower than API, so going to the API is better in the long run, but your worries about system are 99.99% unfounded.
Last edited on
Topic archived. No new replies allowed.