回答
這取決於你的操作系統, 如果你使用Linux:
system("clear");
如果您使用Windows:
system("cls");
但這讓你的應用程序酒糟便攜,是更好要做
cout << string(50, '\n');
這一行將打印行,看起來像終端被「清除」。
50?那是可怕的算法! – 2012-03-07 08:27:11
您可以使用conio.h
中定義的clrscr()
。但爲什麼不問你之前谷歌?
對於使用Clrscr我應該使用哪個頭文件? – Nofuzy 2012-03-07 08:18:01
你在用什麼IDE? – 2012-03-07 08:19:13
我問谷歌之前,來到這裏。谷歌不會創建內容,它可以幫助您通過編制索引來查找內容 – 2012-03-15 07:07:19
你可以嘗試系統方法,例如系統( 「CLS」);
一種方法是輸出'\ f'(對應於ASCII換頁字符,代碼12,行打印機用來彈出頁面,並被一些常見終端和仿真器識別爲清屏)。
這不適用於Windows。
#ifdef _WIN32
/* windows hack */
#else
std::cout << '\f' std::flush;
#endif
在您的編譯器中鏈接conio.h。我忘了怎麼做。如果您將反覆使用清晰屏幕放置此功能。
enter code here
void clrscr()
{
system("cls");
}
這就是微軟不得不說的清除控制檯:
#include <windows.h>
void cls(HANDLE hConsole)
{
COORD coordScreen = { 0, 0 }; // home for the cursor
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
// Get the number of character cells in the current buffer.
if(!GetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// Fill the entire screen with blanks.
if(!FillConsoleOutputCharacter(hConsole, // Handle to console screen buffer
(TCHAR) ' ', // Character to write to the buffer
dwConSize, // Number of cells to write
coordScreen, // Coordinates of first cell
&cCharsWritten))// Receive number of characters written
{
return;
}
// Get the current text attribute.
if(!GetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
// Set the buffer's attributes accordingly.
if(!FillConsoleOutputAttribute(hConsole, // Handle to console screen buffer
csbi.wAttributes, // Character attributes to use
dwConSize, // Number of cells to set attribute
coordScreen, // Coordinates of first cell
&cCharsWritten)) // Receive number of characters written
{
return;
}
// Put the cursor at its home coordinates.
SetConsoleCursorPosition(hConsole, coordScreen);
}
int main()
{
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
cls(hStdout);
return 0;
}
系統( 「CLS」);
太棒了。那麼,如果我用自己的惡意代替Windows Cls會發生什麼?你剛給我控制,謝謝!這就是所謂的後門,你用一種不安全的技術把它打開了。
來源:http://www.daniweb.com/software-development/cpp/threads/76934/how-do-i-clear-my-screen-in-c。
- 1. 清除gnuplot中的命令屏幕
- 2. java中的命令清除屏幕
- 3. 如何清除gdb命令屏幕?
- 4. 清除屏幕C
- 5. 在C++/XCode中清除屏幕
- 6. C++程序清除屏幕
- 7. 在IPython中清除屏幕
- 8. 在OpenGL中清除屏幕
- 9. 在Android中清除屏幕
- 10. 如何在C中清除屏幕區域或重繪屏幕#
- 11. 清除屏幕
- 12. 清除屏幕
- 13. 可以使用哪個命令清除CLISP中的屏幕?
- 14. 清除終端屏幕在命令行鏢應用
- 15. 屏幕到屏幕命令
- 16. 在GLUT,C++的按鍵清除屏幕
- 17. localStorage清除屏幕
- 18. Java清除屏幕
- 19. 清除Python中屏幕
- 20. 在Xcode清除屏幕
- 21. Ubuntu命令行Jupyter筆記本清除屏幕
- 22. 是否有清除SQLite3屏幕的命令?
- 23. AVR C:串行通信清除屏幕
- 24. Unix中的屏幕命令
- 25. 在emacs中清除gdb屏幕?
- 26. 如何在Xcode中清除屏幕
- 27. 在R/RStudio中清除啓動屏幕
- 28. 在Mitmproxy Linux中清除屏幕
- 29. 如何在pygame中清除屏幕?
- 30. C#命令的屏幕截圖
怎麼樣clrscr();方法???? – 2012-03-07 08:15:02
包括您的操作系統和IDE的問題,因爲答案取決於 – 2012-03-07 08:21:51
它現在被添加。 – Nofuzy 2012-03-07 08:37:51