0

(If my question is stupid,it is because i am a student)

In my program when i declare my big vector i get "stack overflow"

   cin >> big_number;
   vector<int> my_vector[big_number];

** stack-overflow** ... (note: in the example above the big_number can take values up to 1.000.000)

In my understanding,this happens because variable-sized vectors are placed on the stack (instead of the default heap).

How can i put this 2d vector on the heap? Is putting the user-defined vector on the heap a "bad practice'?

Ermolai
  • 57
  • 12

1 Answers1

2

You should use vector<vector<int>>

Code would look like

std::cin >> big_number;
std::vector<std::vector<int>> my_vector(big_number);

This will create a vector containing big_number of empty vector<int>