在运行时无法输入

Not being able to enter input during runtime

本文关键字:输入 运行时      更新时间:2023-10-16

当我使用输入编译代码时,它工作正常。但是当我想用用户输入运行它时,它只是不接受输入。它不会给出任何错误。

// kefaa and first steps
// 2 2 1 3 4 1
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, a[n], counter=0, maxIncr=0;
cin >> n;
cin.sync(); 
for(int i = 0; i < n; ++i){
cin >> a[i];
}
for(int i=0; i < n-1; ++i){
if (a[i] <= a[i+1]){
counter += 1;
if(maxIncr<counter)
maxIncr=counter;
}else{
counter=1;
}
}
cout << maxIncr;
return 0;
}

首先,请阅读有关您的包含以及为什么我们不像这样包含的内容。

其次,如果您希望程序运行:

int n; 
cin >> n;
int a[n], counter=0, maxIncr=0;

你有什么样子@UnholySheep写给你的,当 n 尚未赋值时,你初始化 a[n]。