Necessity of writing print functions for containers?

后端 未结 3 737
刺人心
刺人心 2021-01-26 13:40

I use about 6 different C++ containers. I started writing print functions to output the container contents. Is this necessary? I would think this is part of the C++ library?<

3条回答
  •  故里飘歌
    2021-01-26 14:35

    The code you give in your question has a hint as to why it is not part of the standard library. Your code uses square brackets and a comma with no spaces to show the pairs in the map. Other people may want it formatted differently so the options the standards committee had were:

    1. Provide a lot of formatting options.
    2. Provide no formatting options and make everyone who doesn't like their formatting roll their own.
    3. Do nothing and make everyone roll their own

    They went with option three knowing that libraries would be developed that meet people's specific needs.

提交回复
热议问题