📜  cpp 中的 clrscr - C++ (1)

📅  最后修改于: 2023-12-03 14:40:14.736000             🧑  作者: Mango

CLRSCR in C++

Introduction

In C++, clrscr() is a predefined function that clears the screen of the console. It is part of the conio.h library which is used for console input/output operations. clrscr() is a popular function used by programmers to clear the terminal screen during the execution of their program.

Syntax

The syntax of clrscr() is quite simple. It does not take any arguments and the function call looks like this:

clrscr();
Example

Here is an example program that uses clrscr() function to clear the screen.

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
   cout << "This is some text on the console!" << endl;

   getch();        // wait for user input
   clrscr();       // clear screen
   cout << "Screen has been cleared!" << endl;

   getch();        // wait for user input
   clrscr();       // clear screen again
   cout << "Screen has been cleared again!" << endl;

   return 0;
}
Conclusion

In conclusion, clrscr() is a useful function for clearing the terminal screen. It is a simple function that takes no arguments and is a part of the conio.h library. It can improve the overall aesthetics and functionality of console applications by clearing the screen for a more user-friendly experience.