知らない人が少なくないみたいだけど、
std::string/std::wstring 文字列中に '\0' / L'\0' を含んでいてもかまわない。
要は単なるchar/wchar_t列なわけで、バッファとして利用可能。
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
int main() {
string hw = "hello";
hw += '\0';
hw += "world";
// string hw("hello\0world", 11) も可。
assert( hw.size() == 11 );
cout << '[';
for ( char ch : hw ) cout << (ch == '\0' ? '_' : ch);
cout << "]\n";
// '\0' を境に切り分ける
string::size_type nullpos = hw.find('\0');
cout << '[' << hw.substr(0, nullpos) << ']'
<< '[' << hw.substr(nullpos+1) << ']'
<< endl;
}