First, containers consist of many elements, so it is not clear in what format to display the elements of the container. For example, you can display each item on a new line. You can display all elements on a single line, separated by spaces. And you can display all elements on a single line, separated by a comma or a semicolon, etc.
Secondly, containers can contain not only fundamental types, but also user-created types. In this case, it is generally impossible to predict in advance what the output of container elements should look like.
Therefore, in fact, it all comes down to operator overloading to display the elements of the container themselves. Responsibility for operator overloading for user-created types lies with the user. Having such an overloaded operator, it is not difficult to derive all elements of the container. And there are several such methods: you can use standard algorithms, such as std::copy , std::copy_if and others. Or you can use the usual cycles: for , while , do-while . Either use a range-based loop. And you can also set the conditions by which elements will be selected for withdrawal from the container.
As for other languages, this issue is usually solved by the fact that all objects are inherited from one basic object that has a virtual (or non-virtual) function toString (or ToString ). That is, any object that is created by the user already has a default output function to the stream. Or, the newly created objects already have some minimal interface, which also includes the function of converting an object to a string.
In C ++, there is no single object from which all other objects originated, and therefore there is no predetermined function for converting an arbitrary object to a string that can be output to a stream.
Притом, что во многих других языках выводить контейнеры не составляет труда.A well-known topic is that programmers with ++ easily solve tasks that Delphi programmers do not even know about;) - Oleg GranRCM