/*Orion Lawlor's Simple STL Examples, olawlor@acm.org
Shows how to implement a simple std::streambuf for output.
The other way to do this is use the "stupid-named pointers"
method, described in truly excruciating detail here: 
	http://www.mr-edd.co.uk/?p=16
*/
#include <iostream>

class mystreambuf : public std::streambuf {
public:
	// Here's some output from the ostream:
	std::streamsize xsputn(const char *s,std::streamsize n) {
		std::string str(s,n);
		std::cout<<"mystreambuf::sputn('"<<str<<"',"<<n<<");\n";
		return n;
	}
};

int main()
{
	mystreambuf buf;
	std::ostream f(&buf);
	f<<"Yo!";
	f<<"Wazzup?";
	f<<12345;
	char c='x';
	f.write(&c,1);
	return 0;
}
/*<@>
<@> ******** Program output: ********
<@> mystreambuf::sputn('Yo!',3);
<@> mystreambuf::sputn('Wazzup?',7);
<@> mystreambuf::sputn('12345',5);
<@> mystreambuf::sputn('x',1);
<@> */
