VC++中没,那为什么_getch需要这个头文件呢

yuyunliuhen 2007-03-14 01:33:18
VC++中没有<conio.h>这个头文件吧,Cstdio可以从MSDN查得到,

Defines the macros traditionally defined in the Standard C library header <stdio.h>.


#if <TRADITIONAL C HEADERS>
#include <stdio.h>
namespace std {
using ::fclose;
using ::feof;
using ::ferror;
using ::fflush;
using ::fgetc;
using ::fgetpos;
using ::fgets;
using ::FILE;
using ::clearerr;
using ::fopen;
using ::fprintf;
using ::fpos_t;
using ::fputc;
using ::fputs;
using ::fread;
using ::freopen;
using ::fscanf;
using ::fseek;
using ::fsetpos;
using ::ftell;
using ::fwrite;
using ::getc;
using ::getchar;
using ::gets;
using ::perror;
using ::putc;
using ::putchar;
using ::printf;
using ::puts;
using ::remove;
using ::rename;
using ::rewind;
using ::scanf;
using ::setbuf;
using ::setvbuf;
using ::size_t;
using ::sprintf;
using ::sscanf;
using ::tmpfile;
using ::tmpnam;
using ::ungetc;
using ::vfprintf;
using ::vprintf;
using ::vsprintf;
}
#endif

Remarks
Including this header also ensures that the names declared with external linkage in the Standard C library header are declared in the std namespace. In this implementation, the names may or may not also be declared in the global namespace, depending on the specific translation environment.

VC++里面没有<conio.h>这个东西,我又查了下_getch,它 又包含在conio.h里,这是为什么呢.
下面是从MSDN查到的有关_getch

This POSIX function is deprecated beginning in Visual C++ 2005. Use the ISO C++ conformant _getch instead.

Gets a character from the console without echo.


int _getch( void );
wint_t _getwch( void );

Return Value
Returns the character read. There is no error return.


Remarks
The _getch and _getwch functions read a single character from the console without echoing the character. None of these functions can be used to read CTRL+C. When reading a function key or an arrow key, each function must be called twice; the first call returns 0 or 0xE0, and the second call returns the actual key code.

These functions lock the calling thread and are therefore thread-safe. For non-locking versions, see _getch_nolock, _getwch_nolock.

Generic-Text Routine Mappings
Tchar.h routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined
_gettch
_getch
_getch
_getwch

Requirements
Routine Required header Compatibility
_getch
<conio.h>
Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_getwch
<conio.h> or <wchar.h>
Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003


Example
Copy Code
// crt_getch.c
// compile with: /c
// This program reads characters from
// the keyboard until it receives a 'Y' or 'y'.


#include <conio.h>
#include <ctype.h>

int main( void )
{
int ch;

_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );

_putch( ch );
_putch( '\r' ); // Carriage return
_putch( '\n' ); // Line feed
}


...全文
2388 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuyunliuhen 2007-03-14
  • 打赏
  • 举报
回复
conio 这个没有查到啊
Muf 2007-03-14
  • 打赏
  • 举报
回复
查不到的话,那你上面的资料又是哪查的?
yuyunliuhen 2007-03-14
  • 打赏
  • 举报
回复
为什么在MSDN查不到这个conio呢
taodm 2007-03-14
  • 打赏
  • 举报
回复
VC6、VC2005都有啊。
yuyunliuhen 2007-03-14
  • 打赏
  • 举报
回复
还没问完呢,呵呵,就是
Cstdio,与conio的头文件名之间有什么关系吗?
#include
#include
/* 程序多次调用biodkey(),应包含头文件bios.h */
#include
/* 程序多次调用clrscr(),应包含头文件conio.h */
#include nio.h>

#define MAX 100
#define PAGE 2
#define PRINT1 printf("--------------------------------------\n")
#define PRINT2 printf("NUM---NAME---AGE---MOBILE---ADDRESS\n")
#define PRINT3 printf("%d,%s,%d,%s,%s,\n",message[i].num,message[i].name,message[i].age,message[i].mobile[15],message[i].address);


int sum;


struct message_type
{
int num;
char name[15]; /* name应是数组 */
int age;
char mobile[15];
char address[30]; /* address应是数组 */
}message[MAX];


main()
{
int choice;
sum = read_message();
bioskey(0);

do
{
clrscr();
printf("\n\n\n ********通讯录管理系统********\n\n" );
printf(" 1.创建资料\n\n");
printf(" 2.输出资料\n\n");
printf(" 3.资料查询\n\n");
printf(" 4.资料添加\n\n");
printf(" 5.资料删除\n\n");
printf(" 6.资料修改\n\n");
printf(" 7.资料整理\n\n");
printf(" 0.退出系统\n\n");
printf("请选择(0-7):");
scanf("%d",&choice);

switch(choice)
{
case 1: input_message();break;
case 2: output_message();break;
case 3: inquire_message();break;
case 4: insert_message();break;
case 5: del_message();break;
case 6: revise_message();break;
case 7: sort_message();break;
case 0: break;
}
}while(choice!=0);
save_message(sum);
printf("\n -以上资料已保存!-(文件名:messagenotes.txt)\n");
}


/*保存信息*/
save_message(int sum)
{FILE *fp;
int i;
if((fp=fopen("messagenotes.txt","wb"))==NULL)
{printf("读文件错误!\n");
return;
}
for(i=0;iif(fwrite(&message[i],sizeof(struct message_type),1,fp)!=1)
printf("写文件错误!\n");
fclose(fp);
}

/* Function: input_message() */
input_message()
{
int i=0; /* 变量s无用,已删除 */
clrsrc();
printf("\n\n 录入通讯录\n"); /* 笔误 */
printf("\n -------------------------------\n");

do
{
printf("\n 第%d号录入",i+1);
printf("\n 编号:");
scanf("%d",&message[i].num);
if(message[i].num == 0)
break;
printf("\n 姓名:");
scanf("%s",message[i].name);
printf("\n 年龄:");
scanf("%d",&message[i].age);
printf("\n 电话:");
scanf("%s",message[i].mobile); /* message的mobile是数组,不用取址 */
printf("\n 地址:");
scanf("%s",message[i].address);
i++;
}while(i
printf("\n --第%d号录入完毕 --\n",i);
sum = i;
printf("\n 按任意键返回住菜单!"); /* 本语句无效,程序已自动返回菜单 */
}

/* Function: read_message() */
int read_message()
{
FILE *fp;
int i = 0;
if((fp=fopen("messagenotes.txt","rb")) == NULL)
{
printf("\n\n*****暂时有任何保存信息,按任意键进入主菜单选择进行信息录入!*****\n");
return;
}
while(!feof(fp)) /* feof()遇文件结束标志时返回非0值,不能依赖于1 */
{
fread(&message[i],sizeof(struct message_type),1,fp);
if(message[i].num == 0)
break;
else
i++;
}
fclose(fp);
return(i);
}


/* Function: output_message() */
output_message()
{
int i=0,j=0,count,page=1;
clrscr();
printf("\n\n --通讯录资料-- 第%d页\n\n",page);
PRINT2;
PRINT1;

do
{
if(message[i].num != 0)
{
j++;
if(j%PAGE != 0) /* 本if句恒假 */
{
PRINT3;
PRINT1;
}
else
{
PRINT3;
PRINT1;
if(message[i+1].num!=0)
{
print("按任意键继续!");
bioskey(0);
clrscr();
printf("\n\n --通讯录资料-- 第%d页\n\n",++page);
PRINT2;
PRINT1;
}
}
}
i++;
}while(message[i].num != 0);

printf("按任意键返回主菜单!");
bioskey(0);
}


/* Function: insert_message() */
insert_message()
{
int i=sum,j,flag=0;
char choice;
clrscr();
printf("\n\n 添加一条资料\n");
printf(" ---------------------------\n");
do
{
message[i].num = ++sum;
printf("\n 新资料编号:%d",message[i].num);
printf("\n 姓名:");
scanf("%s",message[i].name);
printf("\n 年龄:");
scanf("%d",&message[i].age);
printf("\n 电话:");
scanf("%s",&message[i].mobile[15]);
printf("\n 地址:");
scanf("%s",message[i].address);
printf("\n 要继续吗?(Y/N)");
choice=getch();
if (choice=='y'||choice=='Y')
{printf("\n 继续!\n");
i++;
flag=1;
}
else flag=0;
}while(flag==1);
printf("\n 按任意键返回主菜单!");
bioskey(0);
}


/*删除模块*/
del_message()
{int i=sum,j,flag=0;
char choice;
clrscr();
printf("\n\n 删除一条资料\n");
printf(" ---------------------------\n");
do
{message[i].num=++sum;
printf("\n 删除资料编号:%d",message[i].num);
printf("\n 姓名:");
scanf("%s",message[i].name);
printf("\n 年龄:");
scanf("%d",&message[i].age);
printf("\n 电话:");
scanf("%s",&message[i].mobile[15]);
printf("\n 地址:");
scanf("%s",message[i].address);
printf("\n 要继续吗?(Y/N)");
choice=getch();
if (choice=='y'||choice=='Y')
{printf("\n 继续!\n");
i++;
flag=1;
}
else flag=0;
}while(flag==1);
printf("\n 按任意键返回主菜单!");
bioskey(0);
}


/*修改模块*/
revise_message()
{int i=0,choice,revise_num,flag;
do
{clrscr();
printf("\n 输入要修改的资料编号:");
scanf("%d",&revise_num);
for(i=0;iif(message[i].num==revise_num)
{printf("\n --资料信息--\n");
PRINT1;
PRINT2;
PRINT3;
printf("\n 您要修改哪一项?\n");
printf("\n 1.姓名\n");
printf("\n 2.年龄\n");
printf("\n 3.电话\n");
printf("\n 4.地址\n");
printf("\n 请选择(1-4):");
scanf("%d",&choice);
switch(choice)
{case 1: printf("\n 请输入修改后的姓名:");
scanf("%s",&message[i].name);break;
case 2: printf("\n 请输入修改后的年龄:");
scanf("%d",&message[i].age);break;
case 3: printf("\n 请输入修改后的手机:");
scanf("%s",&message[i].mobile[15]);break;
case 4: printf("\n 请输入修改后的地址:");
scanf("%s",&message[i].address);break;
}
PRINT1;
PRINT2;
PRINT3;
break;
}
if (i==sum)
{printf("\n 无该资料!");
bioskey(0);
}
printf("\n\n 继续修改吗?(Y/N)");
choice=getch();
if (choice=='Y'||choice=='y')
{flag=1;
printf("\n 继续!\n");
}
else flag=0;
}while(flag==1);
printf("\n 按任意键返回主菜单!");
bioskey(0);
}


/* Function: inquire_name() */
inquire_name()
{
int i,choice,j=0; /* 笔误 */
char inquire_name[15]; /* 变量inquire_name应为数组 */
clrscr();
printf("\n 请输入要查询的姓名:");
scanf("%s",inquire_name);

for(i=0; i{ /* 以下语句,在0if(strcmp(message[i].name,inquire_name) == 0)
{
printf("\n --资料--\n");
PRINT1;
PRINT2;
PRINT3;
break; /* 增加 */
}
else
j++;
}
if(j == sum)
printf("\n 查询信息不存在!");
bioskey(0);
}

/* Function: inquire_age() */
inquire_age() /* 对本函数作更改,参与原函数比较 */
{
int i,choice,j=0;
int inquire_age;
clrscr();
printf("\n 请输入要查询的年龄:");
scanf("%d",&inquire_age);
for(i=0; iif(message[i].age == inquire_age)
{
printf("\n --资料--\n");
PRINT1;
PRINT2;
PRINT3;
break;
}
else
j++;
if(j == sum)
printf("\n 查询信息不存在!");
bioskey(0);
}


/* Function: inquire_message() */
inquire_message()
{
int choice; /* 原语句笔误,已改 */

do
{
clrscr();
printf("\n\n\n **********查询资料**********\n\n\n");
printf(" 1.按姓名查询\n\n");
printf(" 2.按年龄查询\n\n");
scanf("%d",&choice);
switch(choice)
{
case 1: inquire_name();break; /* 为函数调用 */
case 2: inquire_age();break; /* 同上 */
case 0: break;
}
}while(choice != 0);
}


/*排序模块*/
sort_num()
{struct message_type *p,*q[MAX];
int i,j,k;
clrscr();
printf("\n 按编号排序\n");
printf("---------------------------------------------\n");
printf("\n 排名 编号 姓名 年龄 手机 地址\n");
p=message;
for(i=0;i{k=i;
for(j=i+1;jif(q[k]->numnum)
k=j;
if(k!=i)
{p=q[i];q[i]=q[k];q[k]=p;}
}
for(i=0;iprintf("\n%d %d %s %d %s %s\n",
i+1,q[i]->num,q[i]->name,q[i]->age,q[i]->mobile[15],q[i]->address);
bioskey(0);
}

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧