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

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -