C语言 如何清除 Code::blocks 中的输出屏幕?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7938331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear the output screen in Code::blocks?
提问by Pranay Khatri
in turbo c++ you could do it like this
在 turbo c++ 中,你可以这样做
#include<conio.h>
void main()
{
clrscr();
}
But in code blocks i cant use this.. :(
但是在代码块中我不能使用这个.. :(
回答by Kanghu
You can use system("cls");with the header #include <cstdlib>. "cls" is a Batch command that works on DOS/Windows. On other systems(UNIX based systems) you might use:cout << "\x1b[2J\x1b[1;1H" << flush;
您可以system("cls");与 header 一起使用#include <cstdlib>。“cls”是一个适用于 DOS/Windows 的批处理命令。在其他系统(基于 UNIX 的系统)上,您可能会使用:cout << "\x1b[2J\x1b[1;1H" << flush;
Never, I repeat, NEVER use "conio.h". Is a deprecated library, that is not a part of standard, and only a few compilers have it.
永远不要,我再说一遍,永远不要使用“conio.h”。是一个不推荐使用的库,它不是标准的一部分,只有少数编译器拥有它。
回答by Mike
Clear Output Screen - Depends on compilers and Operating System, we can use one of the following method depending on the compiler.
清除输出屏幕 - 取决于编译器和操作系统,我们可以根据编译器使用以下方法之一。
- Using
clrscr()- For TurboC Compiler - Using
system("cls")- For TurboC Compiler - Using
system("clear")- For gcc/g++ compiler in Linux
- 使用
clrscr()- 对于 TurboC 编译器 - 使用
system("cls")- 对于 TurboC 编译器 - 使用
system("clear")- 用于 Linux 中的 gcc/g++ 编译器
回答by Alok Paul.
The easiest most straightforward way is to just do it through system function call:
最简单最直接的方法是通过系统函数调用来完成:
#include <stdlib.h>
int main()
{
system("cls");
}
回答by VTodorov
#include<windows.h>
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World ! ! !\n";
system("pause");
system("cls");
}
100% working code.
You need iostream and namespace std only for cout cin etc. The windows header has "cls". It is like system ( " MSDOS_COMMAND " );. Good luck.
100% 工作代码。您只需要 iostream 和命名空间 std 用于 cout cin 等。windows 标题有“cls”。它就像system ( " MSDOS_COMMAND " );. 祝你好运。
回答by Jalal.LinuX
This is ok
还行吧
#include<conio.h>
#include<stdio.h>
int main()
{
printf("Hello!");
getche();
system ("cls");
printf("Bye!");
return 0;
}
回答by Anonymous_User
//try without this-- " using namespace std ".
//尝试没有这个--“使用命名空间std”。
#include<conio.h>
#include<iostream.h>
int main()
{
//using namespace std
clrscr();
}
Let me know if it works.
让我知道它是否有效。
回答by Ammar Saleem
Use system("cls");(for windows) or system("clear");(for GNU/Linux) with header #include <stdlib.h>(If you are programming in C Language) or #include <cstdlib>(If you are programming in C++)
使用system("cls");(对于 Windows)或system("clear");(对于 GNU/Linux)和头文件#include <stdlib.h>(如果您使用 C 语言编程)或#include <cstdlib>(如果您使用 C++ 编程)
Note: #include <conio.h>is not a standard library header file and only provided by few compilers (e.g. TurboC++).
注意:#include <conio.h>不是标准库头文件,仅由少数编译器(例如 TurboC++)提供。

