函数名: clrscr
功 能: 清除文本模式窗口,清屏的意思,即把之前显示出的文字字符去掉,是clear screen的简写
用 法: void clrscr(void);
程序例:
#include <conio.h>
int main (void)
{
int i;
clrscr();
for (i = 0; i < 20; i++)
{
printf("%d\r\n", i);
}
cprintf("\r\nPress any key to clear screen");
getch();
clrscr();
printf("The screen has been cleared!");
getch();
return 0;
}
注意:
①只有在Turbo c 中可以运行 !
②在Turbo C++ 中,需要先
另存为(save as).C格式,才能使用。
另解:
在VC中无法调用该函数,有下列办法:
system("cls");
这种办法的缺点是程序额外运行系统程序执行清屏操作,延长了程序执行时间。
2.自己写函数,这种办法比较快。
/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __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) */
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}
这是我在CSDN里面看到的,并适当的做了添加:
/*清屏函数*/
#include <stdio.h>
#include <windows.h>
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
void MyCls(HANDLE) ;
inline void clrscr(void)
{
HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
MyCls(hStdOut);
return;
}
void MyCls(HANDLE hConsole)
{
COORD coordScreen={0,0};//设置清屏后光标返回的屏幕左上角坐标
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;//保存缓冲区信息
DWORD dwConSize;//当前缓冲区可容纳的字符数
bSuccess=GetConsoleScreenBufferInfo(hConsole,&csbi);//获得缓冲区信息
PERR(bSuccess,"GetConsoleScreenBufferInfo");
dwConSize=csbi.dwSize.X * csbi.dwSize.Y;//缓冲区容纳字符数目
//用空格填充缓冲区
bSuccess=FillConsoleOutputCharacter(hConsole,(TCHAR)' ',dwConSize,coordScreen,&cCharsWritten);
PERR(bSuccess,"FillConsoleOutputCharacter");
bSuccess=GetConsoleScreenBufferInfo(hConsole,&csbi);//获得缓冲区信息
PERR(bSuccess,"ConsoleScreenBufferInfo");
//填充缓冲区属性
bSuccess=FillConsoleOutputAttribute(hConsole,csbi.wAttributes,dwConSize,coordScreen,&cCharsWritten);
PERR(bSuccess,"FillConsoleOutputAttribute");
//光标返回屏幕左上角坐标
bSuccess=SetConsoleCursorPosition(hConsole,coordScreen);
PERR(bSuccess,"SetConsoleCursorPosition");
return;
}
/*测试*/
void main(){
printf("1111") ;
clrscr() ;
}
- memcpy函数用法
memcpy函数用法 .分类: VC++ VC++ mfc matlab 2011-12-01 19:17 14538人阅读 评论(0) 收藏 举报 null 原型:extern void *memc ...
- C语言中malloc()和calloc()c函数用法
C语言中malloc()和calloc()c函数用法 函数malloc()和calloc()都可以用来动态分配内存空间,但两者稍有区别. malloc()函数有一个参数,即要分配的内存空间的大小: ...
- strncpy 用法
strncpy 用法 原型:extern char *strncpy(char *dest, char *src, int n); 用法:#include <string.h> 功能: ...
- malloc函数用法
malloc函数用法 函数声明(函数原型): void *malloc(int size); 说明:malloc 向系统申请分配指定size个字节的内存空间.返回类型是 void* 类型.void* ...
- memset函数用法
1. memset()函数原型是extern void *memset(void *buffer, int c, int count) buffer:为指针或是数组 c:是赋给buffer的值 cou ...
- malloc与free函数用法
在C里,内存管理是通过专门的函数来实现.另外,为了兼容各种编程语言,操作系统提供的接口通常是 C 语言写成的函数声明 (Windows 本身也由C和汇编语言写成). 1 分配内存 malloc 函数 ...
- memset用法详解
原文:http://www.cnblogs.com/PegasusWang/archive/2013/01/20/2868824.html 1.void *memset(void *s,int c,s ...
- C语言中函数strcpy ,strncpy ,strlcpy的用法【转】
转自:http://blog.chinaunix.net/uid-20797562-id-99311.html strcpy ,strncpy ,strlcpy的用法好多人已经知道利用strncpy替 ...
- strcat()与strcpy()用法
1.strcpy (1)原型 extern char *strcpy(char *dest,char *src); (2)用法 #include <cstring> (3)功能 把src所 ...
随机推荐
- C++: Why pass-by-value is generally more efficient than pass-by-reference for built-in (i.e., C-like) types
A compiler vendor would typically implement a reference as a pointer. Pointers tend to be the same s ...
- iOS 获取内存大小使用情况(进度条显示)
一.获取设备内存大小方法 //返回存储内存占用比例 - (NSString *)getFreeDiskspaceRate{ float totalSpace; .f; NSError *error = ...
- linux云计算集群架构学习笔记:用户管理和root用户密码重置
RHEL7用户管理 本节所讲内容: 用户和组的相关配置文件 管理用户和组 RHEL7破解root密码 与windows 相比 LINUX中的用户和账号的作用是一样的. 都是基于用户对访问的资源做控制, ...
- LeetCode 122
Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...
- Windows 8.1 归档 —— Step 1 选择与安装
下面是 Windows 8.1 各版本区别: Windows 8.1 标准版(一般就称之为Windows 8.1): 包括全新的 Windows 商店.Windows 资源管理器.任务管理器等等,还将 ...
- 媒体查询的应用以及在css3中的变革
CSS一直都支持设置与媒体相关联的样式表.它们可以适应不同媒体类型的显示.例如,文档在屏幕显示时使用sans-serif字体,在打印时则使用serif字体.screen和print是两种预定义的媒体类 ...
- Exception与相关
怎么写一个exception类, 直接抛出去,主要是写一个构造函数里面的Msg消息,这个可以提前写出来. try...catch..finally 一般都是一起的,try 中有异常执行语句, catc ...
- 转(C#)Winform中MD5加密
MD5的全称是message-digest algorithm 5(信息-摘要算法,在90年代初由mit laboratory for computer science和rsa data securi ...
- asp.net中webservice与android的json数据交互方式设置
一 .服务器端设置 1.修改web.config 在web.config里面的的system.Web节点添加 <webServices> <protocols> <add ...
- 如何获取Window
[[UIApplication sharedApplication].delegate window]