簡體   English   中英

替代 getch()、gotoxy()、delay()、clrscr()

[英]Substitute for getch(), gotoxy(), delay(), clrscr()

我有一些為 Turbo C 編譯器編寫的舊程序源代碼。我對它們進行了更改,並希望在適用於 Linux 和 Windows 的較新編譯器中重新編譯它們。所以請告訴我什么是最好的替代函數

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

對於 C 和 C++。

對於Unix兼容系統,請查看ncurses庫。

對於Windows系統:

最好是將程序編譯為Windows的控制台應用程序。

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

以下是給定函數的可能替換:

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

在類Unix系統上,您可以使用VT100轉義代碼替換clrscr()和gotoxy()。 clrscr():

std::cout << "\033[2J" << std::flush;

有關gotoxy()的信息,請訪問http://www.termsys.demon.co.uk/vtansi.htm

  1. system("cls"); //clrscr(); #include<stdio.h>
  2. system("pause"); //獲取(); #include<stdio.h>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM