📜  C语言中的cleardevice()函数

📅  最后修改于: 2021-05-26 02:35:56             🧑  作者: Mango

头文件graphics.h包含cleardevice()函数,该函数在图形模式下清除屏幕并将当前位置设置为(0,0)。清除屏幕包括用当前背景色填充屏幕。

句法 :

void cleardevice();

以下是C中cleardevice()的实现:

// C Implementation for cleardevice()
#include 
  
// driver code
int main()
{
    // gm is Graphics mode which is
    // a computer display mode that
    // generates image using pixels.
    // DETECT is a macro defined in
    // "graphics.h" header file
    int gd = DETECT, gm;
  
    // initgraph initializes the
    // graphics system by loading a
    // graphics driver from disk
    initgraph(&gd, &gm, "");
  
    // set the background colour as GREEN
    setbkcolor(GREEN);
  
    // outtext function displays
    // text at current position.
    outtext("Press any key to clear the screen.");
  
    getch();
  
    // cleardevice function
    cleardevice();
  
    outtext("Press any key to exit...");
  
    getch();
  
    // closegraph function closes the
    // graphics mode and deallocates
    // all memory allocated by
    // graphics system .
    closegraph();
  
    return 0;
}

输出:

执行程序时,输出窗口如下所示: 在按任意键时: 要退出,请按任意键。

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。