1.直接调用系统函数 system(“pause”);
例如:
#include
using namespace std;
int main()
{
system(“pause”);
return 0;
}
2.调用getch()函数:需要include<conio.h>
例如:
#include<conio.h>
int main()
{
prinf(“按任意键继续\n”);
getch();
return 0;
}
3.调用getchar()函数:需要include<stdio.h>
例如:
#include<stdio.h>
int main()
{
prinf(“按 Enter 键继续\n”);
getchar();
return 0;
}
4.使用cin的get()函数
例如:
#include
using namespace std;
int main()
{
cout<<“按 Enter 键继续”<<endl;
cin.get();
return 0;
}
注意:只有前两种可以真正实现“按任意键继续”,后两种必需按下Enter 键才行。
清屏函数:system(“cls”);
本文介绍了在C++中使程序暂停等待用户输入的四种方法,包括调用system('pause')、getch()、getchar()及cin.get()函数,并说明了前两种方法能响应任意按键,而后两种则需按Enter键。同时,文章还提到了用于清屏的system('cls')函数。

364

被折叠的 条评论
为什么被折叠?



