2017-05-03 00:14:27 +00:00
|
|
|
/** @example stream1.cc
|
|
|
|
*
|
|
|
|
* An example of using streams to read and write binary files
|
|
|
|
* with some help from the standard range algorithms.
|
|
|
|
*/
|
|
|
|
|
2017-02-08 00:06:50 +00:00
|
|
|
#include <ostd/platform.hh>
|
2016-02-01 23:10:05 +00:00
|
|
|
#include <ostd/io.hh>
|
2016-01-31 22:19:23 +00:00
|
|
|
|
|
|
|
using namespace ostd;
|
|
|
|
|
2017-01-30 18:19:09 +00:00
|
|
|
void print_result(uint32_t x) {
|
2016-01-31 22:19:23 +00:00
|
|
|
writefln("got x: 0x%X", x);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2017-02-16 19:39:05 +00:00
|
|
|
file_stream wtest{"test.bin", stream_mode::WRITE};
|
2016-07-31 19:40:25 +00:00
|
|
|
copy(
|
|
|
|
iter({ 0xABCD1214, 0xBADC3264, 0xDEADBEEF, 0xBEEFDEAD }),
|
2017-01-30 18:19:09 +00:00
|
|
|
wtest.iter<uint32_t>()
|
2016-07-31 19:40:25 +00:00
|
|
|
);
|
2016-01-31 22:19:23 +00:00
|
|
|
wtest.close();
|
|
|
|
|
2017-02-16 19:39:05 +00:00
|
|
|
file_stream rtest{"test.bin"};
|
2016-02-26 15:19:54 +00:00
|
|
|
writefln("stream size: %d", rtest.size());
|
2016-01-31 22:19:23 +00:00
|
|
|
|
2017-02-16 19:39:05 +00:00
|
|
|
for (uint32_t x: map(rtest.iter<uint32_t>(), from_big_endian<uint32_t>())) {
|
2016-01-31 22:19:23 +00:00
|
|
|
print_result(x);
|
2016-07-31 19:40:25 +00:00
|
|
|
}
|
2016-01-31 22:19:23 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-02-07 21:17:15 +00:00
|
|
|
}
|