So I would like to parse a binary file and extract some data from it. The problem I am facing with this is that I need to convert a stream of char
s to a stream of unsigned char
s.
Reading the boost documentation, it seems that boost::iostreams::code_converter
should be the solution for this, so I tried this:
typedef unsigned char uint8_t;
typedef boost::iostreams::stream<boost::iostreams::code_converter<
boost::iostreams::basic_array_source<uint8_t>,
std::codecvt<uint8_t, char, std::mbstate_t> > > array_stream;
array_stream s; //initialized properly in the code
unsigned char asd;
s >> asd;
std::cout << asd << std::endl;
The idea was to specify a codecvt
with InternalType=uint8_t
and ExternalType=char
. Unfortunately this does not compile.
So the question is: how do I convert a stream of char
s to a stream of uint8_t
s?