If you have used the
std::string and C-style string, you must think the
std::string is so convenient in memory management. You can append/delete chars in any way without considering about the memory allocation. But there isn't any class for a byte stream in the std library. So, here's an implementation for a byte stream. I often use it when using Windows APIs, such as those for file operation, network, etc.
Here's the test code, I think it's so simple that a detailed explanation is not needed:
using namespace std;
dc << 100
dc >> i >> s >> b;
cout << i << endl
<< s << endl
<< b << endl;
I wrote the code just after reading the book << Exceptional C++ >>, so I think this can be called an Exception-Safe class :). Hope you enjoy it, and thanks for any advice. Finally, thanks for reading this article, and sorry for my poor English.