I\'m trying to hold the screen on my output using the header file
, but I don\'t know any equivalent function to the getch()
&
This is what I usually use:
#include<iostream>
...
std::getchar();
getch() and clrscr() will work with C++. Include conio.h
However, if you CANNOT (for some reason) include conio.h,
how about cin>>dummy_var with a display message asking the user to press enter?
I understand that this is an old question but I am going to answer nonetheless because people may be looking for an answer to a similar question.
conio.h
is an (ancient) Windows and MS-DOS/PC-DOS C library that was, and still is used for very basic, bare-metal keyboard input and handling in a Windows/DOS environment.
Both getch()
and clrscr()
are non-standard additions by this header, and should be avoided when possible for the standard C functions. getch()
can usually be replaced with scanf()
, fread()
, in C and std::cin
and std::cin.get
in C++. As for clrscr()
, the closest you can get is:
for(int i = 0; i < 100; i++)
{
printf("\n");
}
OR:
There is also ncurses.h
on *nix environments. Here's a link to some info about that.
if you work on windows you can use system("pause"), this will give you "press any key to continue" message.
The platform-specific function getch()
from conio.h has two special features:
The echoing is done by the terminal outside of the C/C++ environment. It can only be controlled by manipulating the terminal. Also, it is nearly impossible to get unbuffered I/O with the iostream.h header.
Therefore it is not possible to get anywhere near getch()
using iostream.h alone.
(There are plenty of getch()
implementations around, e.g. using termios.h to disable echoing.)
just use cin.get();