streams

Streams are abstractions that can accept input or produce output bit-by-bit, cumulatively.

When you’re working with bytes as numeric values – rather than characters – there’s a gotcha that can burn you when you try to stream those values out using standard library streams. The insertion operator for all character types – char, signed char, and unsigned char – prints the character value, not the numeric value. Lots of beginners struggle with this and even many experts don’t know the easy fix. Continue Reading

Over ten years ago I first wrote an article about reading an entire file into memory in C++. It has become my most copied work (always without attribution), and every time I’ve set up a new site or blog, I’ve included an updated version – which again usually ranks among the most popular pages or posts there. So, it’s time again for the 2014 version of How to read an entire file into memory in C++. Continue Reading

One can generally count on Stack Overflow for excellent, high-quality C++ advice. Several C++ experts regularly contribute (I see Howard Hinnant frequently, for example). But Stack Overflow won’t always give you good answers. Here’s a case where a request for a simple solution generates 10+ responses with code ranging from ~10-30 lines – and in one case over 60 lines spread over two files! – that use macros, templates, proxy objects, and in more than a few cases have surprising and likely annoying side effects… for something that could have been solved with a single character. Yes. One… single… character. Continue Reading

A problem I come across rather frequently has to do with the fact that input in C++ requires a pre-existing variable of the correct type, which either has to be uninitialized or initialized to some “safe” value. There’s a third option, though, and it’s the topic of my first Tippet. Continue Reading