在c++中system("pause");用来暂停黑窗口
在c++程序中,窗口有时会一闪就消失,如果不想消失,需添加
system("pause");
但要注意在return 语句之前添加,并且要头文件#include<stdlib.h>
具体分析
system()就是调用(DOS)系统命令(和shell命令)
pause,就是DOS命令集合中的暂停命令
当程序中有system("pause");语句时,从该程序里调用了“pause"命令,让操作系统暂停该程序进程的执行,同时程序运行到该语句时,会在窗口上显示"Pree any key to continue..."当用户按下任意键,程序继续往后执行。
例子
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
cout << "hello world" << endl;
system("pause");//暂停
cout << "猫猫是猪咪" << endl;
return 0;
}
运行时先出现:
按下任意键后: