Open utterances-bot opened 10 months ago
@hackingcpp is.read(reinterpret_cast<char*>(i), sizeof(i));
should be is.read(reinterpret_cast<char*>(i), sizeof(&i));
and so on
I agree with Kooonnn's viewpoint, and the test code I wrote below:
os.write(reinterpret_cast<char const*>(i), sizeof(i));
should beos.write(reinterpret_cast<char const*>(&i), sizeof(i));
If the above code is not modified, it will cause runtime errors:
It will attempt to read memory address
114514
instead of the memory address where variable i
is located, which obviously does not meet our expectations
@kooonnn & @XY0797 -- thanks for spotting the obvious mistake, I'll fix it soon -- the "&" got lost, because "&" is a special html character and I forgot to escape it in the original source code from which the html page is generated -- but @kooonnn also made a little mistake, the &i
should be inside the reinterpret_cast
and not inside the sizeof
C++ File Input & Output | hacking C++
An introduction to basic file input and output in C++ using standard iostreams.
https://hackingcpp.com/cpp/std/file_streams.html