back inserter in vector c 2b 2b

Solutions on MaxInterview for back inserter in vector c 2b 2b by the best coders in the world

showing results for - "back inserter in vector c 2b 2b"
Isabelle
18 Jun 2018
1// back_inserter example
2#include <iostream>     // std::cout
3#include <iterator>     // std::back_inserter
4#include <vector>       // std::vector
5#include <algorithm>    // std::copy
6
7int main () {
8  std::vector<int> foo,bar;
9  for (int i=1; i<=5; i++)
10  { foo.push_back(i); bar.push_back(i*10); }
11
12  std::copy (bar.begin(),bar.end(),back_inserter(foo));
13
14  std::cout << "foo contains:";
15  for ( std::vector<int>::iterator it = foo.begin(); it!= foo.end(); ++it )
16	  std::cout << ' ' << *it;
17  std::cout << '\n';
18
19  return 0;
20}