$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] reinterpret_cast boost integer
From: Brad Tilley (kj4eit_at_[hidden])
Date: 2012-02-05 11:17:19
> What doesn't work about it? The std iostreams print char types as
> (extended) ascii characters. What if you cast the type to a wider
> integer just when printing?
>
> Brian
Thanks Brian. I wasn't aware that iostream would do that. You're
right, uint8_t is big enough, iostream just prints out the extendend
ASCII char rather than the int on std::cout. This works:
void process_uint8_t( const std::string& bytes )
{
const boost::uint8_t * data_ptr;
boost::uint8_t data;
data_ptr = reinterpret_cast<const boost::uint8_t*>(bytes.data());
data = *data_ptr;
// print ascii
std::cout << data << "," << sizeof(data) << std::endl;
// print int
std::cout << (unsigned int)data << "," << sizeof(data) <<
std::endl;
}
Thanks for pointing that out.
Brad