7 Associative containers and files

This chapter covers

  • Filling and using associative containers
  • Pairs and tuples
  • Reading from files
  • Random samples

We have used vectors several times now but haven’t used an associative container yet. An associative container holds key-value pairs, giving us a lookup table or dictionary. In this chapter, we will use dictionaries to create a game of answer smash. We’ll provide two clues, each a definition of a word. The end of the first word will overlap with the start of the next word, giving the answer. For example, a vector is a “sequential container supporting dynamic resizing,” and a torch could be defined as a “lit stick carried in one’s hand,” so smashing together the words vector and torch gives the answer ...

Get Learn C++ by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.