现在我要在矩形之后再显示一天line(0,0,100,100) 的直线,应该怎么编写?

#include "graphics.h" 
main() 

int driver,mode; 
driver=VGA; 
mode=VGAHI; 
initgraph(&driver,&mode,"C:\\JMSOFT\\DRV"); 
bar(200,200,400,350); 
getch(); 
closegraph(); 


这个程序是显示一个矩形 
现在我要在矩形之后再显示一天line(0,0,100,100)
的直线 应该怎么编写?(在显示直线的时候矩形消失)。

慕的地8271018
浏览 96回答 1
1回答

哔哔one

比较简单,你可以使用清除图形屏幕函数cleardevice();先显示填充矩形,然后按任意键矩形消失再显示直线,再按任意键退出程序。&nbsp;程序我已在tc/win-tc下运行通过。&nbsp;#include <stdio.h>&nbsp;#include <stdlib.h>&nbsp;#include <graphics.h>&nbsp;main()&nbsp;{&nbsp;int driver,mode;&nbsp;driver=VGA;&nbsp;mode=VGAHI;&nbsp;initgraph(&driver,&mode,"C:\\JMSOFT\\DRV");&nbsp;bar(200,200,400,350);&nbsp;getch();&nbsp;cleardevice(); /*或者用这一句system("cls");*/line(0,0,100,100);&nbsp;getch();&nbsp;closegraph();&nbsp;}&nbsp;-----------------------------------------------------------------&nbsp;当然还可以使用延时函数,这样就不用按任意键再显示直线了。&nbsp;#include <stdio.h>&nbsp;#include <stdlib.h>&nbsp;#include <graphics.h>&nbsp;main()&nbsp;{&nbsp;int driver,mode;&nbsp;driver=VGA;&nbsp;mode=VGAHI;&nbsp;initgraph(&driver,&mode,"C:\\JMSOFT\\DRV");&nbsp;bar(200,200,400,350);&nbsp;sleep(2);/*延时2秒*/&nbsp;cleardevice();&nbsp;line(0,0,100,100);&nbsp;getch();&nbsp;closegraph();&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP