cpp_weekly icon indicating copy to clipboard operation
cpp_weekly copied to clipboard

Why I'm still using std::cout

Open lefticus opened this issue 2 months ago • 4 comments

lefticus avatar Nov 03 '25 19:11 lefticus

As a side note, could you also explain why std::cout has so much hate?

fcolecumberri avatar Nov 04 '25 14:11 fcolecumberri

As a side note, could you also explain why std::cout has so much hate?

Because it is buffered output and, more importantly it is usually used in conjunction with std::endl which flushes the buffer resulting in a very slow operation.

Sorry if this was not the place to reply, just trying to contribute, though I'm terribly curious to know why lefticus still uses std::cout! :) :)

clinaresl avatar Nov 04 '25 15:11 clinaresl

Additionally, the default configuration makes it very slow, which surprises people coming from "slower" languages that can output to stdout faster by default: https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio

LB-- avatar Nov 04 '25 20:11 LB--

is that about std::cout over std::print or?

std::print sadly is rather slow, so for short messages i go with std::cout, if i need formatting then really just good old concatenation. And i still dislike std::cout so sometimes it is just printf (hey - if it works... that is not for production-code)

As a side note, could you also explain why std::cout has so much hate?

Because it is buffered output and, more importantly it is usually used in conjunction with std::endl which flushes the buffer resulting in a very slow operation.

Both those things are just configurable default behaviours. And both of them have very valid reason for being so. It is just rather unintuitive for newcomers and global state is (also for good reasons) fround upon.

casurin avatar Nov 24 '25 19:11 casurin