As in the title. How can I clear console in C++?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
Use
system("cls")
to clear the screen:For pure C++
You can't. C++ doesn't even have the concept of a console.
The program could be printing to a printer, outputting straight to a file, or being redirected to the input of another program for all it cares. Even if you could clear the console in C++, it would make those cases significantly messier.
See this entry in the comp.lang.c++ FAQ:
OS-Specific
If it still makes sense to clear the console in your program, and you are interested in operating system specific solutions, those do exist.
For Windows (as in your tag), check out this link:
Edit: This answer previously mentioned using
system("cls");
, because Microsoft said to do that. However it has been pointed out in the comments that this is not a safe thing to do. I have removed the link to the Microsoft article because of this problem.Libraries (somewhat portable)
ncurses is a library that supports console manipulation:
For Linux/Unix and maybe some others but not for Windows before 10 TH2:
will reset terminal.
edit: completely redone question
Simply test what system they are on and send a system command depending on the system. though this will be set at compile time
This is a completely new method!
The easiest way would be to flush the stream multiple times ( ideally larger then any possible console ) 1024*1024 is likely a size no console window could ever be.
The only problem with this is the software cursor; that blinking thing ( or non blinking thing ) depending on platform / console will be at the end of the console, opposed to the top of it. However this should never induce any trouble hopefully.