2 phương pháp này cũng gần tương tự với lệnh clrscr vào turbo CỞ đây bao gồm 2 cách:
Cách 1 : sử dụng 1 hàm vào C++
1/ chức nă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 trong VC. Thì sau khoản thời gian thực hiện lệnh này, cả màn hình sẽ tất cả màu nền trùng với cái hàm nền mà các bạn gọi trước đó.VD:Trình tự call như sau:– hàm màu bao gồm nền xanh– hàm system(“cls”);kết quả là cả screen có nền màu xanh, chưa phải nền màu đen như ban sơ nữa
4/ Code
#include "stdlib.h"void main()system("cls");Cách 2 : thiết kế 1 hàm tiến hành việc này bằng phương pháp dùng những hàm console
1/ tính nă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, cực nhọc 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 set the buffer"s attributes accordingly */FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten );/* put the cursor at (0, 0) */SetConsoleCursorPosition( hConsole, coordScreen );return;5/ code thử nghiệm hoàn chỉnh
#include 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; /* lớn 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 phối 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 benhvienranghammatsaigon.vn");cls();