Does the C++ standard mandate poor performance for iostreams, or am I just dealing with a poor implementation?

Every time I mention slow performance of C++ standard library iostreams, I get met with a wave of disbelief. Yet I have profiler results showing large amounts of time spent in iostream library code (full compiler optimizations), and switching from iostreams to OS-specific I/O APIs and custom buffer management does give an order of magnitude … Read more

How to print (using cout) a number in binary form?

I’m following a college course about operating systems and we’re learning how to convert from binary to hexadecimal, decimal to hexadecimal, etc. and today we just learned how signed/unsigned numbers are stored in memory using the two’s complement (~number + 1). We have a couple of exercises to do on paper and I would like … Read more

Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?

I just found a comment in this answer saying that using iostream::eof in a loop condition is “almost certainly wrong”. I generally use something like while(cin>>n) – which I guess implicitly checks for EOF. Why is checking for eof explicitly using while (!cin.eof()) wrong? How is it different from using scanf(“…”,…)!=EOF in C (which I … Read more