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



## MetalheadGautham (Feb 3, 2009)

*Hope this helps newbies.*

clrscr()

```
system("clear");      //Needs cstdlib headder file so do #include<cstdlib>
```
getch()

```
getchar();            // Needs stdio.h so do #include<stdio.h>
```
And yeah, always use 
	
	



```
using namespace std;
```
 after including headders. Need that because actual usage of cout otherwise is std::cout and not cout, and so on.


----------



## Faun (Feb 3, 2009)

that system call will cost you jackpot


----------



## MetalheadGautham (Feb 3, 2009)

T159 said:


> that system call will cost you jackpot


why ?


----------



## Liverpool_fan (Feb 3, 2009)

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)

^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)

namespace is not needed !!!


----------



## MetalheadGautham (Feb 4, 2009)

^^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)

Thank you dude!!  I always had this confusion..!


----------

