c++中为什么有时候可以加system("pause") ? 什么时候能加?什么时候不能加呢

c++中为什么有时候可以加system("pause") ?
什么时候能加?什么时候不能加呢?

    首先说明一下这个函数的目的是为了让控制台暂停,同理也可以用getchar(),cin等来实现

    调用函数就需要相应的头文件,而system的头文件是stdlib.h,所以想用他就得要包含stdlib.h

    c++里有很多头文件已经包含了这个文件,如

    #include <iostream>
    #include <cstdlib>
    #include <string>

但是并不是所有的c++头文件都引用了,有的时候恰好没有引用到stdlib.h就无法使用了

温馨提示:内容为网友见解,仅供参考
第1个回答  2015-09-11
加个头文件试下;
#include <stdlib.h>

再加语句system("pause");
相似回答