c++ - Why is this code on vectors giving runtime error? -


what wrong code , why giving runtime error ?

    #include <iostream>     #include <vector>     using namespace std;      int main() {          vector < int > a[2];         a[0][0]=1;         a[1][0]=2;         cout << a[0][0];         cout << a[1][0];         return 0;     } 

also please correct .

why giving runtime error ?

because 2 vectors empty, can't access elements using [].

also please correct .

    vector < int > a[2];     a[0].push_back(1);     a[1].push_back(2); 

Comments

Popular posts from this blog

python - matpltolib navigation toolbar edit curves and parameters line color automatically changes issue -

node.js - Nodejs javascript implementation of PBEWithMD5AndTripleDES/CBC/PKCS5Padding -