请输入您要查询的百科知识:

 

词条 clrscr
释义

函数名: clrscr

功 能: 清除文本模式窗口 清屏的意思 就是把之前显示出的文字字符去掉 跟cmd里面的清屏的功能是一样的 实际上是clear screen的简写

用 法: void clrscr(void);

程序例:

#include <conio.h>

int main(void)

{

int i;

clrscr();

for (i = 0; i < 20; i++)

cprintf("%d\\r\", i);

cprintf("\\r\Press any key to clear screen");

getch();

clrscr();

cprintf("The screen has been cleared!");

getch();

return 0;

}

只有在Turbo c 中可以运行 !在Turbo C++ 中,需要先另存为(save as).C格式,才能使用。

注:在VC中无法调用该函数,有下列办法:

1.#include <windows.h>

system("cls");

这种办法的缺点是程序额外运行系统程序执行清屏操作,延长了程序执行时间。

2.自己写函数,这种办法快

这是从微软MSDN得到的方法:

/* Standard error macro for reporting API errors */

#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \\

on line %d\", __FILE__, GetLastError(), api, __LINE__);}

void cls( HANDLE hConsole )

{

COORD coordScreen = { 0, 0 }; /* here's where we'll home the

cursor */

BOOL bSuccess;

DWORD cCharsWritten;

CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */

DWORD dwConSize; /* number of character cells in

the current buffer */

/* get the number of character cells in the current buffer */

bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );

PERR( bSuccess, "GetConsoleScreenBufferInfo" );

dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

/* fill the entire screen with blanks */

bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',

dwConSize, coordScreen, &cCharsWritten );

PERR( bSuccess, "FillConsoleOutputCharacter" );

/* get the current text attribute */

bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );

PERR( bSuccess, "ConsoleScreenBufferInfo" );

/* now set the buffer's attributes accordingly */

bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,

dwConSize, coordScreen, &cCharsWritten );

PERR( bSuccess, "FillConsoleOutputAttribute" );

/* put the cursor at (0, 0) */

bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );

PERR( bSuccess, "SetConsoleCursorPosition" );

return;

}

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/3/14 19:13:30