strong disagree on printf... maybe there's some modern typesafe C++ way to do the same thing, but format specifiers are way easier to remember than all the ways of modifying iostream.
[0] https://en.cppreference.com/w/cpp/utility/format/format
[1] https://fmt.dev
std::string str = "Values: ";
for (auto &[key, val]: dict) {
str.append("%s: %d, ", key, value);
}
This is so much nicer to use than stringstream, and it's also so much more efficient! You could allocate a "big enough" string at the beginning, and then you would have no more allocations. You could also reuse the string, so you can avoid almost all allocations for the lifetime of the program. This is basically impossible to do with stringstream: it's just insane about copies and allocations, and it's more or less impossible to reuse buffers.The C++ format strings are an improvement, but just this simple thing (a super straight-forward translation of printf to C++ std::strings) is basically all you would ever need. C more or less got it right in the 70s, and then C++ spent decades with its own (significantly worse) solution.
Constrast with cout, which will happily let you print out the wrong variable. It won't print out garbage of course because it helpfully knows to print out the int differently, but it can't give you a warning. Also, it's difficult to do localization with it.