VS2010暫停編譯界面


注:文章主要知識點來源於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 72

int 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;
}        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM