xtd 0.2.0
Loading...
Searching...
No Matches
redirect_output.cpp

Shows how to use xtd::console class.

#include <xtd/io/path>
#include <xtd/io/file>
#include <xtd/console>
#include <xtd/environment>
using namespace xtd;
using namespace xtd::io;
auto main() -> int {
auto output_file_path = path::combine(path::get_temp_path(), "xtd_example_write.txt");
auto output_stream = file::open_write(output_file_path);
console::set_out(output_stream);
console::write_line("Item1");
console::write_line("Item2");
console::write_line("Item3");
output_stream.close();
console::set_out(console::open_standard_output());
console::write_line(string::join(environment::new_line(), file::read_all_lines(output_file_path)));
file::remove(output_file_path);
}
// This code can produce the following output :
//
// Item1
// Item2
// Item3
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10