[英]Is clrscr(); a function in C++?
I've looked everywhere for this function and cannot find the header files to make this work. 我到处寻找这个功能,找不到头文件来使这个工作。 It says clrscr() undeclared which brings me to the question.
它说clrscr()未声明,这让我想到了这个问题。 Is clrscr();
是clrscr(); a function in C++?
C ++中的函数?
It used to be a function in <conio.h>, in old Borland C compilers. 它曾经是旧的Borland C编译器中<conio.h>中的一个函数。
It's not a C++ standard function. 它不是C ++标准函数。
And before someone posts the usual "please email me the conio.h file" request, can I point out that this ancient Borland header file only contained the declaration of the function. 在有人发布通常的“请给我发电子邮件conio.h文件”请求之前,我是否可以指出这个古老的Borland头文件只包含该函数的声明。 You would also need the supporting Borland library, which will not be compatible with any modern C++ compilation system.
您还需要支持Borland库,它与任何现代C ++编译系统都不兼容。
As mentioned before, clrscr() is from turbo c++, inside conio.h 如前所述,clrscr()来自turbo c ++,在conio.h中
For all intents and purposes, conio.h is "non standard", and as such should be probably avoided. 对于所有意图和目的,conio.h是“非标准的”,因此应该可以避免。
I tend to use the precompiler to choose what to use for a simple clear screen, and just call the operating system's clear program.... it's smart enough to know how "tall" the screen is. 我倾向于使用预编译器来选择用于简单清晰屏幕的内容,并且只需调用操作系统的清晰程序......它足够聪明,可以知道屏幕的“高”程度。
// somewhere in the program
#define WINDOWS 1
void console_clear_screen() {
#ifdef WINDOWS
system("cls");
#endif
#ifdef LINUX
system("clear");
#endif
}
In windows, you may want to look at the windows.h, You can interact with the windows console directly using a "handle", often noted in code as an hWin. 在Windows中,您可能需要查看windows.h,您可以使用“句柄”直接与Windows控制台进行交互,通常在代码中将其标记为hWin。
In linux, i've had good luck with curses/ncurses, although it is a little confusing at first. 在linux中,我对curses / ncurses有好运,虽然起初它有点令人困惑。
update Calling system programs (clear.exe?)is a potential security risk - if someone is able to hijack the system call somehow thru an alternate avenue, they can force your program to do strange things. 更新调用系统程序(clear.exe?)是一个潜在的安全风险 - 如果有人能够以某种方式通过一个替代途径劫持系统调用,他们可以强制你的程序做一些奇怪的事情。 My recommendation is to dig into your platform's console api to get these things done.
我的建议是深入你的平台的控制台api来完成这些工作。
你必须包含此函数的头文件
#include <conio.h>
you can use the system cls command to clear the output screen.. 您可以使用system cls命令清除输出屏幕..
clrscr() is from turbo c++, inside conio.h and conio.h is "non standard", and as such should be probably avoided. clrscr()来自turbo c ++,在conio.h中,conio.h是“非标准”,因此应该可以避免。 example
例
#include<windows.h>
main()
{
some code....;
system("cls");
some more code;
}
its tested and works.. i use dev c++ with mingw compiler.. :) 它的测试和工作..我使用dev c ++与mingw编译器.. :)
A web search says the header file you want is 'conio.h' - I haven't tried it out, so no guarantees. 网络搜索说你想要的头文件是'conio.h' - 我还没有尝试过,所以没有保证。 Its existence may also depend on what platform you are compiling against.
它的存在也可能取决于你正在编译的平台。
On Linux I always use: 在Linux上我总是使用:
void clrscr(void)
{
fprintf(stdout, "\033[2J"); // clean screen
fprintf(stdout, "\033[1;1H"); // move cursor to the first line
}
On Unix-like systems you can use VT100 escape codes. 在类Unix系统上,您可以使用VT100转义码。
std::cout << "\033[2J" << std::flush;
See http://www.termsys.demon.co.uk/vtansi.htm 见http://www.termsys.demon.co.uk/vtansi.htm
The easiest way to clear the screen in real C++ is to just send out a bunch of blank lines. 在真正的C ++中清除屏幕的最简单方法是发送一堆空白行。 Of course this is assuming that stdout is directed at the screen and not a file:
当然这是假设stdout指向屏幕而不是文件:
for (int i = 0; i < 80; ++i)
cout << "\n";
cout << endl;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.