tags:

views:

1132

answers:

3

I'm trying to hold the screen on my output using the header file <iostream.h>, but I don't know any equivalent function to the getch() & clrscr() functions of <conio.h> in <iostream.h> or any other C++ library. Are there any such functions?

+2  A: 

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?

Crimson
thanks...it worked...
Aayush
-1, because conio.h is not part of the C standard.
Vijay Mathew
+1 because most interesting things you can do with C and C++ are actually not in the standard. Neither standard is intended to be complete, and the fact that you can include headers other than the standard-mandated ones is very much by design.
MSalters
+4  A: 

The conio.h functions are compiler extensions to the language, not part of C or C++. There isn't a direct replacement in standard C++.

For getch(), int ch = std::cin.get(); is probably the closest equivalent -- but bear in mind that this will read from buffered standard input, whereas I think the conio.h getch does an unbuffered read.

Any implementation of clrscr() is going to be very platform-dependent -- not all screens or terminals have a notion of clearing, and those that do have wildly differing ways to access that functionality.

If you need to treat the terminal as something other than a set of character streams, your best bet is probably to look for a library which hides the details of the underlying terminal, screen or console from you. If you're on a UNIXish system, look at the curses or ncurses library; I don't know of any suggestions for other OSes.

Stephen Veiss
thanks...this worked...
Aayush
+1  A: 

if you work on windows you can use system("pause"), this will give you "press any key to continue" message.

barism