Làm thế nào để bạn xóa màn hình giao diện điều khiển trong c?

     
Trần Hán Huy – bdskingland.com

2 phương pháp này cũng gần tương đương với lệnh clrscr trong turbo CỞ đây bao gồm 2 cách:

Cách 1 : dùng 1 hàm trong C++

1/ tác dụng :

xóa hết màn hình.

2/Thư viện kèm theo:

stdlib.h hoặc windows.h

3/ khuyết điểmNếu bạn áp dụng hàm màu sắc trong VC. Thì sau khoản thời gian thực hiện nay lệnh này, cả màn hình hiển thị sẽ gồm màu nền trùng với loạ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 có nền xanh– hàm system(“cls”);kết trái là cả màn hình hiển thị có nền màu xanh, chưa hẳn nền màu đen như ban sơ nữa

4/ Code

#include "stdlib.h"void main()system("cls");Cách 2 : lập trình sẵn 1 hàm tiến hành việc này bằng cách dùng những hàm console

1/ công dụng :

xóa không còn màn hình.

2/Thư viện kèm theo:

windows.h

3/ khuyết điểm

Hàm tương đối dài, cạnh tranh 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 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 trang chủ thecursor */DWORD cCharsWritten;CONSOLE_SCREEN_BUFFER_INFO csbi; /* khổng lồ 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;void main()printf("Chao mung ban den voi bdskingland.com");cls();