How to clear the output screen in Code::blocks?

霸气de小男生 提交于 2020-01-04 13:06:53

问题


in turbo c++ you could do it like this

#include<conio.h>
void main()
{
     clrscr();
}

But in code blocks i cant use this.. :(


回答1:


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;

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.




回答2:


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



回答3:


The easiest most straightforward way is to just do it through system function call:

#include <stdlib.h>

int main()
{
    system("cls");
}



回答4:


#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.




回答5:


//try without this-- " using namespace std ".

#include<conio.h>
#include<iostream.h>
int main()
{
//using namespace std
 clrscr();
}

Let me know if it works.




回答6:


This is ok

#include<conio.h>
#include<stdio.h>
int main()
{
    printf("Hello!");
    getche();
    system ("cls");
    printf("Bye!");
    return 0;
}



回答7:


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++)

Note: #include <conio.h> is not a standard library header file and only provided by few compilers (e.g. TurboC++).



来源:https://stackoverflow.com/questions/7938331/how-to-clear-the-output-screen-in-codeblocks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!