2 cách này cũng gần tương tự với lệnh clrscr vào turbo CỞ đây có 2 cách:
Cách 1 : dùng 1 hàm trong C++
1/ công dụng :
xóa hết màn hình.2/Thư viện kèm theo:
stdlib.h hoặc windows.h3/ khuyết điểmNếu bạn áp dụng hàm màu sắc trong VC. Thì sau thời điểm thực hiện tại lệnh này, cả màn hình hiển thị sẽ gồm màu nền trùng với mẫu hàm nền mà chúng ta gọi trước đó.VD:Trình tự gọi như sau:– hàm màu tất cả nền xanh– hàm system(“cls”);kết trái là cả screen có nền color xanh, chưa phải nền màu đen như thuở đầu nữa
4/ Code
#include "stdlib.h"void main()system("cls");Cách 2 : thiết kế 1 hàm triển khai việc này bằng phương pháp dùng những hàm console
1/ công dụng :
xóa hết màn hình.2/Thư viện kèm theo:
windows.h3/ khuyết điểm
Hàm khá dài, nặng nề nhớ4/ code hàm
void cls( )HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);COORD coordScreen = 0, 0 ; /* here"s where we"ll home thecursor */DWORD cCharsWritten;CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */DWORD dwConSize; /* number of character cells in the current buffer *//* get the number of character cells in the current buffer */GetConsoleScreenBufferInfo( hConsole, &csbi );/* fill the entire screen with blanks */FillConsoleOutputCharacter( hConsole, (TCHAR) " ",dwConSize, coordScreen, &cCharsWritten );/* get the current text attribute */GetConsoleScreenBufferInfo( hConsole, &csbi );/* now mix the buffer"s attributes accordingly */FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten );/* put the cursor at (0, 0) */SetConsoleCursorPosition( hConsole, coordScreen );return;5/ code test hoàn chỉnh
#include void cls( )HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);COORD coordScreen = 0, 0 ; /* here"s where we"ll trang chủ thecursor */DWORD cCharsWritten;CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */DWORD dwConSize; /* number of character cells in the current buffer *//* get the number of character cells in the current buffer */GetConsoleScreenBufferInfo( hConsole, &csbi );/* fill the entire screen with blanks */FillConsoleOutputCharacter( hConsole, (TCHAR) " ",dwConSize, coordScreen, &cCharsWritten );/* get the current text attribute */GetConsoleScreenBufferInfo( hConsole, &csbi );/* now mix the buffer"s attributes accordingly */FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten );/* put the cursor at (0, 0) */SetConsoleCursorPosition( hConsole, coordScreen );return;void main()printf("Chao mung ban den voi bugthecao.com");cls();