为什么C语言运行闪下就没了

system("pause");

getchar();到底用哪个,上面是VC编译器的??可为什么我貌似不能用它

因为计算机的运行速度过快,C语言只运行一下就消失了。你可以采用以下方式;

           #include<cstdlib>

           #include<cstdio>

           int main(){
              int a,b;

              scanf("%d%d",&a,&b);

              printf("%d\na+b);

              system("pause");//或while(1);

              return 0;

          }

其中#include<cstdlib>与system("pause")是一对,而while(1);则不需要特殊头文件.

运行结果如下

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-12-07

如果程序没有问题,那就是编译器的问题:

解决方案有两种:

1.主函数的结束位置加system("pause");同时需要请引入头文件:#include<stdlib.h>

例如:

#include<stdlib.h>
#include<stdio.h>
int main()
{
    printf("helloWord!");
    system("pause");
    return 0;
}

2.主函数的结束位置加getchar();同时需要引入头文件:#include<string.h>

例如:

#include<string.h>
#include<stdio.h>
int main()
{
    printf("helloWord!");
    getchar();
    return 0;
}

第2个回答  2013-10-01
system("pause"); 用这个要加上头文件include<windows.h>

getcgar() 要加上stdio.h 头文件
这两个VC编译器都能用本回答被提问者采纳
第3个回答  2013-10-01
调试运行时用ctrl+f5试试
第4个回答  2013-10-01
头文件没包含吧。