Create a file and fill it up with zeroes:
dd if=/dev/zero of=/tmp/zeroes count=1
Write this little program to extract the first unsigned integer it encounters in the file.
#include <assert.h>
#include <fstream>
int main()
{
std::ifstream reader( "/tmp/zeroes", std::ios_base::binary );
uint32_t number;
reader >> number;
assert( !reader.fail() );
}
Why is the assert triggered?
Because /dev/zero
delivers binary zeros, not the character
'0'
, and >>
does (or tries to do) a conversion from text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With