Alternative function in iostream.h for getch() of conio.h?

后端 未结 10 1058
无人共我
无人共我 2020-11-30 09:55

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() &

10条回答
  •  醉话见心
    2020-11-30 10:36

    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.

提交回复
热议问题