Skip to Main Content
C++ Primer, Fifth Edition
book

C++ Primer, Fifth Edition

by Stanley B. Lippman, Josée Lajoie, Barbara E. Moo
August 2012
Intermediate to advanced content levelIntermediate to advanced
976 pages
30h 17m
English
Addison-Wesley Professional
Content preview from C++ Primer, Fifth Edition

11.3.2. Adding Elements

The insert members (Table 11.4 (overleaf)) add one element or a range of elements. Because map and set (and the corresponding unordered types) contain unique keys, inserting an element that is already present has no effect:

vector<int> ivec = {2,4,6,8,2,4,6,8};    // ivec has eight elementsset<int> set2;                           // empty setset2.insert(ivec.cbegin(), ivec.cend()); // set2 has four elementsset2.insert({1,3,5,7,1,3,5,7});      // set2 now has eight elements

Table 11.4. Associative Container insert Operations

Image

The versions of insert that take a pair of iterators or an initializer list work similarly to the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional C++, 6th Edition

Professional C++, 6th Edition

Marc Gregoire
C++ How to Program, 10/e

C++ How to Program, 10/e

Paul Deitel, Harvey Deitel

Publisher Resources

ISBN: 9780133053043Purchase Link