When I try to input to vector by following code, I get a segmentation fault
as shown below.
I defined the vector and set N
, and tried to input a vector with N
elements.
What is the root cause of this?
#include <iostream>
#include <vector>
using namespace std;
int N;
vector<int> A(N);
int main(){
cin>>N;
for(int i=0;i<N;i++) cin>>A[i];
}
[ec2-user@ip-10-0-1-187 ]$ ./vector_input
1
1
Segmentation fault