visual studio 2010 - I am not able to use vector header file -


i want use vector header file guess there error in it. have attached image file containing error. when ever run code error shown in image. please tell me how resolve it.

#include <iostream> #include <conio.h> #include <vector>  using namespace std; int main() { vector<vector<int>> rmat; vector<int> r = { 1, 2, 3, 4, 5 };  (int = 0; < 3; i++) (int j = 0; j < 5; j++) {     rmat[i][j] = r[j]; }  (int = 0; < 3; i++) {     (int j = 0; j < 5; j++)         cout << rmat[i][j] << "\t";     cout << "\n"; }   _getch(); return 0; } 

error on runtime

read error message:

vector subscript out of range

you have created empty vector,

vector<vector<int>> rmat; 

and access nonexisting elements,

rmat[i][j] = r[j]; 

which results in undefined behaviour in case resulted in helpful exception being thrown.

grab a book on c++ , learn basics first.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -