I want to create a std::istream object with a stream buffer object that can take raw byte data from array of unsigned char. I searched and found this Link
However they create the stream buffer based on array char:
struct membuf : std::streambuf
{
membuf(char* begin, char* end) {
this->setg(begin, begin, end);
}
};
I thought about type caste , but i don't want to modify the original data.So how i can it be done using unsigned char.
With
std::istreamyou cannot useunsigned charexplicitly, because it is a typedef forstd::basic_istream<char>docs. You can cast your buffer pointers tochar*Note that conversion of values greater than
CHAR_MAXtocharis implementaion defined (of course, only if you will actually use this values aschar).Or you can try to use
std::basic_istream<unsigned char>(I have not tried it though).