cplusplus vector assign

Solutions on MaxInterview for cplusplus vector assign by the best coders in the world

showing results for - "cplusplus vector assign"
Anna
14 Jun 2017
1// vector assign
2#include <iostream>
3#include <vector>
4
5int main ()
6{
7  std::vector<int> first;
8  std::vector<int> second;
9  std::vector<int> third;
10
11  first.assign (7,100);             // 7 ints with a value of 100
12
13  std::vector<int>::iterator it;
14  it=first.begin()+1;
15
16  second.assign (it,first.end()-1); // the 5 central values of first
17
18  int myints[] = {1776,7,4};
19  third.assign (myints,myints+3);   // assigning from array.
20
21  std::cout << "Size of first: " << int (first.size()) << '\n';
22  std::cout << "Size of second: " << int (second.size()) << '\n';
23  std::cout << "Size of third: " << int (third.size()) << '\n';
24  return 0;
25}