Filling containers from std::istream iterators
In the last recipe, we learned how we can assemble compound data structures from an input stream and then fill lists or vectors with those.
This time, we make it a little bit harder by filling an std::map
from standard input. The problem here is that we cannot just fill a single structure with values and push it back into a linear container like a list or a vector is because map
divides its payload into key and value parts. It is, however, not completely different, as we will see.
After studying this recipe, we will feel comfortable with serializing and deserializing complex data structures from and to character streams.
How to do it...
We are going to define another structure like in the last recipe, but this time we are going to fill it into a map, which makes it more complicated because this container maps from keys to values instead of just holding all values in a list:
- First, we include all the needed headers and declare that we use the
std
...