insert vector to end of vector c++
vector<int> a;
vector<int> b;
a.insert(a.end(), b.begin(), b.end());
// or
a.insert(std::end(a), std::begin(b), std::end(b));
insert vector to end of vector c++
vector<int> a;
vector<int> b;
a.insert(a.end(), b.begin(), b.end());
// or
a.insert(std::end(a), std::begin(b), std::end(b));
insert vector
#include <iostream>
#include <vector>
void print_vec(const std::vector<int>& vec)
{
for (auto x: vec) {
std::cout << ' ' << x;
}
std::cout << 'n';
}
int main ()
{
std::vector<int> vec(3,100);
print_vec(vec);
auto it = vec.begin();
it = vec.insert(it, 200);
print_vec(vec);
vec.insert(it,2,300);
print_vec(vec);
// "it" no longer valid, get a new one:
it = vec.begin();
std::vector<int> vec2(2,400);
vec.insert(it+2, vec2.begin(), vec2.end());
print_vec(vec);
int arr[] = { 501,502,503 };
vec.insert(vec.begin(), arr, arr+3);
print_vec(vec);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us