Explore the instructor's solution to the challenge as well as alternative ways a correct solution may have been produced.
- [Instructor] So here is my solution.…We will start with a file that is very similar…to the last map example code we just wrote.…So notice how the main function, starting at line 11,…first defines a map update called hotel…which has a key that is an integer…and the content is a string.…And then starting at line 17, we have the same round…of insertions we have been using.…
So we will reuse that code.…And finally, starting at line 31, we have the lines of code…that print out the content of the map.…So I hope you can see that this application…of the map container we just wrote,…works very well for this challenge.…So we will start writing the remaining part…of the testing code.…I will start that in line 36.…Now we will try to enter a new entry with an existing key.…
We will get that integer value the usual way,…and we will assign that to the first element…of the temporary pair.…Then we ask for a name,…and assign it to the second element of the pair,…and we are ready to insert this entry into the hotel map.…
We do that by means of the insert function.…
- Why the STL is important
- Containers and iterators
- Vectors and lists
- Stacks and dequeues
- Associative containers
Skill Level Advanced
1. The Standard Template Library
2. Vectors and Lists
3. Stacks, Queues, and Deques
4. Associative Containers
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.