1.直接调用系统函数 system("pause");
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 system("pause"); 6 return 0; 7 }
2.调用getch()函数:需要include<conio.h>
1 #include<conio.h> 2 int main() 3 { 4 prinf("按任意键继续\n"); 5 getch(); 6 return 0; 7 }
3.调用getchar()函数:需要include<stdio.h>
1 #include<stdio.h> 2 int main() 3 { 4 prinf("按 Enter 键继续\n"); 5 getchar(); 6 return 0; 7 }
4.使用cin的get()函数
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 cout<<"按 Enter 键继续"<<endl; 6 cin.get(); 7 return 0; 8 }
注意:只有前两种可以真正实现“按任意键继续”,后两种必需按下Enter 键才行。

浙公网安备 33010602011771号