<conio.h>
2.如果是为了实现控制台的Press
any
key
to
continue_代码如下:
#include
<stdio.h>
#include
<conio.h>
void
press()
{
printf("Press
any
key
to
continue")
getch()
}
void
main()
{
press()
return
}
#include <stdio.h>#include <stdlib.h>
int main(int argc, char const *argv[])
{
int a,b,c
while(scanf("%d %d",&a,&b)==2){
c=a+b
printf("%d+%d=%d\n",a,b,c)
}
system("pause")
return 0
}
简单点,在main上面定义一个宏,注意引用的时候不需要再带分号了。#define PAUSE system("pause")
main()
{
PAUSE//不需要再加分号
}
如此,控制台调试简单程序的时候,当程序执行完成就会暂停,显示结果。
而如果是复杂的程序,比如多线程、延迟程序、实时程序等,即时间线敏感的程序在循环中间加这句会使程序挂起。此时建议使用中断跟踪或者
cout<<"按任意键继续..."<<endl
getchar()
也可以定义成宏
#define STOP cout <<"按任意键继续..." <<endlgetchar()