# C++primer 10.4.1 sessions

Source: Internet
Author: User

Exercise 10.26

Back_inserter creates an iterator that uses push_back.
Front_inserter creates an Push_front iterator.
Inserter Create an iterator that uses insert. This function receives the second argument, which must be an iterator to the given container. The element will be inserted before the element represented by the given iterator.

Exercise 10.27

`1#include <iostream>2#include <string>3#include <iostream>4#include <string>5#include <vector>6#include <algorithm>7#include <list>8#include <functional>9#include <iterator>Ten using namespacestd; One using namespaceplaceholders; A  - voidElmdups (vector<string> &vec, list<string> &); -  the intMain () - { -vector<string> words{" the","Quick","Red","Fox","jumps"," Over"," the","Slow","Red","Turtle" }; -list<string>Li; + elmdups (words, Li); -      for(auto C:li) +cout << C <<Endl; ASystem"Pause"); at     return 0; - } -  - voidElmdups (vector<string>& Vec, list<string> &Li) - { - sort (Vec.begin (), Vec.end ()); in unique_copy (Vec.begin (), Vec.end (), Back_inserter (LI)); -}`

Exercise 10.28

`1#include <iostream>2#include <vector>3#include <list>4#include <algorithm>5 6 using namespacestd;7 8 intMain ()9 {Tenvector<int>Vec; Onelist<int> vec2 = {Ten, One, A},VEC3 = {Ten, One, A},VEC4 = {Ten, One, A}; A      for(inti =1; I <=9; ++i) - Vec.push_back (i); -  the copy (Vec.cbegin (), Vec.cend (), Front_inserter (VEC2)); -      for(Auto it = Vec2.begin (); It! = Vec2.end (); + +it) -cout << *it <<" "; -cout <<Endl; +  - copy (Vec.cbegin (), Vec.cend (), Back_inserter (VEC3)); +      for(Auto it = Vec3.begin (); It! = Vec3.end (); + +it) Acout << *it <<" "; atcout <<Endl; -  - copy (Vec.cbegin (), Vec.cend (), Inserter (Vec4,vec4.begin ())); -      for(Auto it = Vec4.begin (); It! = Vec4.end (); + +it) -cout << *it <<" "; -cout <<Endl; in     return 0; -}`

C++primer 10.4.1 sessions

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.