I have a class that represents a buffer in memory
class Buffer
{
public:
Buffer(const char* buffer, size_t size)
:m_buffer(buffer), m_size(size)
{
}
const char* m_buffer;
size_t m_size;
};
I need to overload operator<< on this class so that it can be written to a std::stringstream like this
char arr[] = "hello world";
Buffer buf(arr, 11);
std::stringstream ss;
ss << buf;
How do I do this? Note that the memory buffer might have NULL chars in between. Also, since the memory buffer can be large, I want to avoid making any extra copies of this (other than the copy into the stringstream).