Flux RSS

C++ Streams suck


This one is a short one (and actually, more an excuse to test highlight.js), but C++ Streams really, really suck. You can say whatever you want, they are the spawn of the devil. Case in point:
#include <iostream>
#include <iomanip>

void hexDump(
    const unsigned char * data,
    size_t size,
    std::ostream & str)
{
    size_t addr = 0;
    str << std::hex
        << std::setfill('0')
        << std::nouppercase
        << std::noshowbase;
    while (addr < size) {
        str << std::setw(8)
            << addr
            << ":   ";
        for (int i = 0; i < 16 && addr < size; i++) {
            str << std::setw(2)
                << static_cast<unsigned int>(data[addr++])
                << " ";
        }
        str << std::endl;
    }
    str << std::resetiosflags;
}

Comments

1. On Monday, January 21 2013, 03:09 by Pixel

And all of this to display something like this:

00000000: 55 89 e5 83 ec 38 c7 45 f4 00 00 00 00 c7 44 24
00000010: 04 f1 8b 04 08 8b 45 10 89 04 24 e8

2. On Monday, January 21 2013, 05:20 by Oliver "kfsone" Smith

"<<" and ">>" are for bits and amusing french quotes (which are about as common as single bits). Anyone who says otherwise is secretly trying to bring about the apocalypse.

3. On Monday, January 21 2013, 11:28 by Tom

French quotes are like this: « »