libostd/examples/stream2.cc

39 lines
885 B
C++
Raw Normal View History

2016-01-31 23:19:23 +01:00
#include <ostd/algorithm.hh>
#include <ostd/string.hh>
2016-02-02 00:10:05 +01:00
#include <ostd/io.hh>
2016-01-31 23:19:23 +01:00
using namespace ostd;
int main() {
writeln("writing sample file...");
2016-05-25 18:12:28 +02:00
FileStream wtest{"test.txt", StreamMode::write};
2016-01-31 23:19:23 +01:00
String smpl =
"This is a test file for later read.\n"
"It contains some sample text in order to see whether "
"things actually read correctly.\n\n\n"
""
"This is after a few newlines. The file continues here.\n"
"The file ends here.\n";
2016-01-31 23:19:23 +01:00
copy(smpl.iter(), wtest.iter());
wtest.close();
2016-05-25 18:12:28 +02:00
FileStream test{"test.txt"};
2016-01-31 23:19:23 +01:00
writeln("## WHOLE FILE READ ##\n");
2016-05-25 18:12:28 +02:00
String ts1{test.iter()};
2016-01-31 23:19:23 +01:00
writefln("-- str beg --\n%s-- str end --", ts1);
test.seek(0);
writeln("\n## PART FILE READ ##\n");
2016-05-25 18:12:28 +02:00
String ts2{test.iter().take(25)};
2016-01-31 23:19:23 +01:00
writefln("-- str beg --\n%s\n-- str end --", ts2);
return 0;
2016-02-07 22:17:15 +01:00
}