DIGIT-ARC read-only archive · snapshot: July 23, 2026

C & C++ getch() and clrscr() functions in Linux

8 posts · originally from https://geek.digit.in/community/threads/c-c-getch-and-clrscr-functions-in-linux.107889/

MetalheadGautham
MetalheadGautham Original post #1
Feb 3, 2009 at 7:54 AM
Hope this helps newbies.

clrscr()
Code:
system("clear");      //Needs cstdlib headder file so do #include<cstdlib>
getch()
Code:
getchar();            // Needs stdio.h so do #include<stdio.h>
And yeah, always use
Code:
using namespace std;
after including headders. Need that because actual usage of cout otherwise is std::cout and not cout, and so on.
Faun
Faun #2
Feb 3, 2009 at 8:12 AM
that system call will cost you jackpot
Liverpool_fan
Feb 3, 2009 at 6:31 PM
system("clear") is NOT exactly same as clrscr() and gives a warning when I try it.
abc.c:7: warning: implicit declaration of function ‘system’
abc.c:8: warning: control reaches end of non-void function


(you can avoid the first warning by stdlib.h but the second one stays)

Also I think, Linux users don't need a clrscr() 'coz:
(1) It will not go according to usual conventions used. For instance there are no terminal programs I have used which actually clear the space.
(2) Newbies or even amateurs who generally want to program in Linux should use Geany. It's excellent.
MetalheadGautham
Feb 4, 2009 at 2:21 PM
^Fully agree, though I don't get the errors.

1. Yup. We guys don't like it when a program abruptly clears the valuble output.

2. WTH ? Geany ? How does the IDE have any thing to do with a function ?


Anyway, I posted this because newbies and switches from windows may need something to make their windows apps compatible with linux.
damngoodman999
Feb 4, 2009 at 2:25 PM
namespace is not needed !!!
MetalheadGautham
Feb 4, 2009 at 2:29 PM
^^Yes it is. Unless for stuff like cin, cout, etc you replace them with std::cin, std::cout, etc, which is time consuming.
josephcs
Feb 12, 2009 at 3:56 PM
Thank you dude!! :) I always had this confusion..!