C++primer 11.3.5 Sessions

Source: Internet
Author: User
Tags sessions

Exercise 11.27

For Multimap, counting the number of occurrences of a keyword will be good, but it is more appropriate for a map to find a keyword;

Exercise 11.28

1#include <iostream>2#include <string>3#include <Set>4#include <map>5#include <algorithm>6#include <vector>7#include <algorithm>8#include <iterator>9 Ten using namespacestd; One  A intMain () - { -vector<int> VEC = {1,2,3,4,5 }; thevector<int> vec2 = {6,7,8,9,Ten }; -     strings ="T"; -     stringS1 ="B"; -map<string, vector<int>> m ={{S,vec},{s1,vec2}}; +Auto it = M.find ("T"); -cout << (*it). First <<" "; +      for(Auto &i: (*it). Second) Acout << i <<" "; atcout <<Endl; -System"Pause"); -     return 0; -}

Exercise 11.29

Upper_bound: The insertion position iterator that points to the found element without affecting sorting;

Lower_bound: Ibid.

Equal_range: An iterator pair, with two iterators pointing to where the element should be inserted

Exercise 11.30

POS is an iterator pair, with two iterators pointing to the first position of the lookup element and the position after the last element of the lookup element, Pos.first refers to its first iterator, which is the keyword after the dereference, and in the call second is the value of the keyword;

Exercise 11.31

1#include <iostream>2#include <string>3#include <Set>4#include <map>5#include <algorithm>6#include <vector>7#include <algorithm>8#include <iterator>9 Ten using namespacestd; One  A intMain () - { -multimap<string,string>authors; the     stringstr, str1; -     stringbook{"ASD"}; -      while(Cin >> STR >>str1) -     { + Authors.insert ({str, str1}); -     } + authors.erase (book); A      for(auto c:authors) at     { -cout << C.first <<" "<< C.second <<Endl; -     } -System"Pause"); -     return 0; -}

Add a method, the problem is not to use the Find function

1#include <iostream>2#include <string>3#include <Set>4#include <map>5#include <algorithm>6#include <vector>7#include <algorithm>8#include <iterator>9 Ten using namespacestd; One  A intMain () - { -multimap<string,string>authors; the     stringstr, str1; -     stringBook"ASD"); -      while(Cin >> STR >>str1) -     { + Authors.insert ({str, str1}); -     } +Auto it =authors.find (book); A      for(; (*it). First = =Book ;) atit = authors.erase (it);//Note the type returned here erase -      for(auto c:authors) -     { -cout << C.first <<" "<< C.second <<Endl; -     } -System"Pause"); in     return 0; -}

Exercise 11.32

See above

C++primer 11.3.5 exercises

Related Article

Contact Us

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.