add functions to redirect input/output

those two multiply the output into a file:

void redirect_output(const char *filename);
void redirect_output(std::string const &filename)

those two read everything from a file:

redirect_input(const char *filename);
redirect_input(std::string const& filename);

both can be resetted using:

void reset_input();
reset_output();
This commit is contained in:
Johannes Kapfhammer 2019-10-28 21:26:54 +01:00
parent d64bc6b9ed
commit 080e3f1261
3 changed files with 105 additions and 1 deletions

View file

@ -27,6 +27,9 @@ signed main() {
a.foo();
a.bar(3,4,"hi");
print("this should not be in the output file");
redirect_output("example.out");
auto [i, j] = read<int, int>();
print(i, j);
@ -68,4 +71,12 @@ signed main() {
print(map<int, string>{{3,"three"},{1,"one"}});
print(tuple{unordered_map<int, string>{{3,"three"},{1,"one"}}});
print(unordered_set<int>{3,1,4});
redirect_input("example.in");
print("reading from example.in:", read_string());
redirect_input("example.in");
print("reading from example.in:", read_string());
print("this is the last line on example.out");
reset_output();
print("this is stdout only");
}