系统( "pause" ) 不工作,任何人都可以看到我缺少什么吗?

system("pause") not working, can anyone see what I'm missing?

本文关键字:什么 任何人 pause 工作 系统 都可以      更新时间:2023-10-16

我的程序有错误,不让我编译。唯一的错误从系统("暂停")开始,但我不明白为什么我有错误,因为我和我一直做程序一样。任何人都可以看到可能的问题是什么吗?代码如下:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ 
 //Declarations
     int SIZE = 10;
     int NUMBERS[10];
     int i;
     int j;
     int temp;
 for (int i = 0; i < SIZE; i++)
 {
     cout << "Please enter a number: " << endl;
     cin >> NUMBERS[i];
 }
 for (int i = 0; i < SIZE; i++)
 {
     for (int j = 0; j < SIZE; j++)
     {
         if (NUMBERS[j] > NUMBERS[j+1])
         {
           temp = NUMBERS[j];
           NUMBERS[j] = NUMBERS[j+1];             
           NUMBERS[j+1] = temp;
         }
     }
 }
 cout << "Sorted List" << endl;
 cout << "===========" << endl;
 for (int i = 0; i < SIZE; i++)
     cout << "Number " << i + 1 << ": " << NUMBERS[i] << endl;
 }
   system("pause");
   return 0;
 }
 for (int i = 0; i < SIZE; i++) {
                             // ^^^ add this missing bracket
     cout << "Number " << i + 1 << ": " << NUMBERS[i] << endl;
 }
^^^  // closing bracket, but has no opening match

当然,在这种情况下,您可以跳过大括号(因为正文只有一行),所以这也是解决方案:

 for (int i = 0; i < SIZE; i++)
     cout << "Number " << i + 1 << ": " << NUMBERS[i] << endl;