Genuinely surprised and confused by “print” and “println”

> Genuinely surprised and confused by “print” and “println”

I was too. Looking at [0], I'm guessing it's meant to bring these benefits over old-school "printf":

- Leverages the type system to avoid mismatches between the format string and the arguments.

- Adds Python- / Rust-style support for position-based substitutions, e.g. "{1}".

- Like Rust (I think; I'm still learning Rust) you can specify per-type formatters.

But I'm still confused about:

- How this relates to the standard library's iostream system. It seems pretty redundant.

- Why "println" exists.

[0] https://en.cppreference.com/w/cpp/io/print

iostreams are horrible to use, especially if you want to format your output and they blow up compilation to a mythical degree. People go to great lengths to avoid them and I agree with them.

print/println are based on the fmt library (https://github.com/fmtlib/fmt), which had it's first release in 2015, so it's roughly as old as Rust afaik. It's mainly inspired by Python formatting.

Having per-type formatters is just a logical conclusion of having type-safe formatting.

iostreams are for all kinds of io (which includes stdin/stdout), while fmt is entirely dedicated to formatting strings. Those things are related, but not the same. cout and cerr and such will probably be entirely superseeded by print/println (I hope), but it doesn't make iostreams generally redundant.

println adds a newline and you want to be able to choose, so there is print and println.