OHexStreambuf is a specialization of FBB::OFilterStreambuf inserting all the characters it receives to a destination file as 2-character wide hexadecimal values. Optionally a maximum linelength can be specified.
Note that all information received by an OHexStreambuf object is inserted as (a series of) hexadecimal values, not only plain characters. E.g., when inserting the value 123 the characters '1', '2' and '3' are successively inserted and so this will result in the string 313233 being inserted into the destination stream.
The destructor writes any buffered information to the destination stream and will then flushes the destination stream.
This member's return value is undefined if no maximum line length was requested.
This function does not verify whether its argument is properly formed. A properly formed argument consists of an even number of hexadecimal number characters ('0' until '9', 'a' until 'f' (or uppercase)). For improperly formed arguments the return value is undefined.
#include <iostream>
#include <bobcat/ohexstreambuf>
using namespace std;
using namespace FBB;
int main()
{
OHexStreambuf ohex(cout, 40);
ostream out(&ohex);
out << cin.rdbuf();
if (ohex.size())
cout << '\n';
}