STL vector<int> push_back() method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

STL vector<int> push_back() method

suppose i have the following type vector<int> v1; in normal case , push_back(int ) but i need , v1.push_back(vector <int>); //need to overload push_back() to push_back(vector <int>)

12th May 2021, 4:38 PM
𝖆𝖙.𝖚𝕷
𝖆𝖙.𝖚𝕷 - avatar
1 Answer
+ 3
Something like this also works: #include <iostream> #include <vector> using namespace std; int main() { vector<vector<int>> twoD; twoD.push_back({1,2,3,4,5}); twoD.push_back({6,7,8,9,10}); vector<int> data{11,12,13,14,15}; twoD.push_back(data); return 0; } If you want to override then: https://stackoverflow.com/questions/13836881/overriding-push-back-c
12th May 2021, 4:50 PM
Rohit