clrscr()
函数用于清除控制台屏幕上的所有字符和光标位置,以便于显示新的内容。然而,clrscr()
函数在C语言标准库中并不存在,它是特定编译器或操作系统提供的一个扩展函数。
下面是几个常用的清屏函数的示例:
system("cls")
函数来清除控制台屏幕上的内容。示例代码如下:#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
int main() {
printf("This is some content on the screen.\n");
Sleep(2000); // 等待2秒
system("cls"); // 清除屏幕内容
printf("Screen is now cleared.\n");
return 0;
}
system("clear")
函数来清除屏幕内容。示例代码如下:#include <stdio.h>
#include <stdlib.h>
int main() {
printf("This is some content on the screen.\n");
sleep(2); // 等待2秒
system("clear"); // 清除屏幕内容
printf("Screen is now cleared.\n");
return 0;
}
请注意,system()
函数可以执行系统命令,这意味着它可能会导致一些安全风险,因此在使用时要小心。另外,清除屏幕内容的具体方法可能因编译器、操作系统或终端类型而异。