Substitute for getch(), gotoxy(), delay(), clrscr()

前端 未结 3 670
终归单人心
终归单人心 2021-01-13 07:48

I have some old program source code that I wrote for Turbo C compiler.I made changes to them and want to recompile them in newer compilers for Linux and Windows.So please te

相关标签:
3条回答
  • 2021-01-13 08:04

    On Unix-like systems you can use VT100 escape codes for replacing clrscr() and gotoxy(). clrscr():

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

    See http://www.termsys.demon.co.uk/vtansi.htm for gotoxy() and more.

    0 讨论(0)
  • 2021-01-13 08:21

    For Windows systems:

    Best is to compile the program as a console application for windows.

    You can directly use the Windows API for console windows and console output. Take a look at the MSDN: Windows Console functions

    Here are possible replacements for the given functions:

    • getch(): use _getch() from conio.h
    • delay()/sleep(): use the windows Sleep() function
    • clrscr(): write your own clrscr() function by using FillConsoleOutputCharacter() and FillConsoleOutputAttribute()
    • gotoxy(): use SetConsoleCursorPosition()
    0 讨论(0)
  • 2021-01-13 08:24

    Take a look at the ncurses library, for Unix compatible systems.

    0 讨论(0)
提交回复
热议问题