替换getch(),gotoxy(),delay(),clrscr()

5 c c++

我有一些我为Turbo C编译器编写的旧程序源代码.我对它们进行了更改,并希望在Linux和Windows的新编译器中重新编译它们.所以请告诉我什么是最好的替代函数

getch(),delay()/ sleep(),clrscr(),gotoxy()

用于C和C++.

Aln*_*tak 15

对于Unix兼容系统,请查看ncurses库.


小智 7

对于Windows系统:

最好是将程序编译为Windows的控制台应用程序.

您可以直接使用Windows API进行控制台窗口和控制台输出.看一下MSDN:Windows控制台功能

以下是给定函数的可能替换:

  • getch():使用conio.h中的_getch()
  • delay()/ sleep():使用windows Sleep()函数
  • clrscr():使用FillConsoleOutputCharacter()和FillConsoleOutputAttribute()编写自己的clrscr()函数
  • gotoxy():使用SetConsoleCursorPosition()