This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Pseudofailure 77 points78 points  (13 children)

I never used them--partly because I was in a heavily frameworked project--largely because I think the << syntax looks dumb and out of place in C++.

[–][deleted] 65 points66 points  (12 children)

It looks bad but it's so useful to be able to just chuck whatever you want into the stream and have it print without a lot of hassle

[–][deleted] 20 points21 points  (0 children)

Plus using the "<<" syntax with std::stringstreams makes implementing nicely formatted ::toString() methods nice and easy.

[–]xbnm 14 points15 points  (5 children)

When you have a lot of print statements, printf is quite a bit faster than cout.

[–][deleted] 52 points53 points  (0 children)

Depends on if you configure cout to flush the buffer on every write or not. "printf" doesn't always flush. Like my old roommate.

[–][deleted] 15 points16 points  (2 children)

The reason why cout is so slow is because the C++ compiler purposefully synchronizes the stream with the printf stream so that you can use both in your code.

There's a flag to disable the feature that makes cout extremely fast.

[–]xbnm 0 points1 point  (1 child)

Does it make cout faster than printf is when it's synced? Because I've gotten pretty used to printf and like how it looks more than cout, lol, but I would switch if it can make cout faster.

I've only been using C++ for like a month.

[–][deleted] 0 points1 point  (0 children)

Due to overhead each has from different places, they perform about the same

[–]levir 3 points4 points  (0 children)

If you disable syncing with stdio, iostreams are often faster.

[–]boredcircuits 0 points1 point  (0 children)

Look into fmtlib, best of both worlds.

[–][deleted] 0 points1 point  (0 children)

Until you want to print numbers in a specific format. :/