溫馨提示×

c語言刷新屏幕功能怎么實現(xiàn)

小億
604
2023-08-17 21:50:20
欄目: 編程語言

在C語言中,可以使用標(biāo)準(zhǔn)庫函數(shù)system("cls")來實現(xiàn)刷新屏幕的功能。system("cls")會調(diào)用系統(tǒng)的命令行來執(zhí)行cls命令,從而清空屏幕上的內(nèi)容。

以下是一個示例代碼:

#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Hello, world!\n");
printf("Press any key to clear the screen.\n");
getchar();  // 等待用戶按下任意鍵
system("cls");  // 清空屏幕
printf("Screen cleared!\n");
return 0;
}

當(dāng)用戶按下任意鍵后,屏幕上的內(nèi)容會被清空,然后打印"Screen cleared!"。

0