VS2010暂停编译界面

来源:互联网 发布:php上传文件原理 编辑:程序博客网 时间:2024/05/16 14:40

注:文章主要知识点来源于https://www.felix021.com/blog/read.php?981

本人主要是按照自己的理解略微整理,感谢原博主Felix201的分享!


正文如下


刚上手VS2010的小伙伴们,可能会苦恼编译界面一闪而过,确实,这个在VC2006压根是不存在的,具体解决办法有三,如下:

  1. 在程序末加getchar();
  2. 添加头文件#include "stdlib.h" ,并在程序末添加system("pause");;
  3. 在需要暂停的地方写入死循环while(1); ,按下CTRL+C可以退出。

注:在涉及到输入函数scanf();时,方法1失效(可使用N+1个getchar();其中N为输入数据的个数);建议使用方法2;勿使用方法3。


具体代码表现如下:

/***************************************************//使用循环进行数组处理***************************************************/#include "stdafx.h"#include "stdio.h"#include "stdlib.h"#define SIZE 2#define PAR 72int main(void){    int index;    int score[SIZE];    int sum=0;    float average;    printf("Enter %d golf scores:\n",SIZE);    for(index=0;index<SIZE;index++)    {        scanf("%d",&score[index]);    }    printf("The scores input in are as follows:\n");    //Good Habits:使用程序输出或“回显”刚刚输入的值,这样有助于确保程序处理了您所期望的数据    for(index=0;index<SIZE;index++)    {        printf("%5d",score[index]);    }    printf("\n");    for(index=0;index<SIZE;index++)    {        sum+=score[index];    }    average=(float)sum/SIZE;    printf("Sum of scores = %d,average = %0.2f\n",sum,average);    //getchar();    //getchar();    //getchar();    system("pause");    return 0;}        

 

原创粉丝点击