xtd 0.2.0
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);
output_stream.close();
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
static void set_out(const std::ostream &os)
Sets the out property to the specified std::ostream object.
static std::ostream open_standard_output()
Acquires the standard output stream.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static xtd::string new_line() noexcept
Gets the newline string defined for this environment.
static std::ofstream open_write(const xtd::string &path)
Opens an existing file for writing.
static xtd::array< xtd::string > read_all_lines(const xtd::string &path)
Opens a text file, reads all lines of the file, and then closes the file.
static void remove(const xtd::string &path)
Deletes the specified file.
static xtd::string get_temp_path() noexcept
Returns the path of the current user's temporary folder.
static xtd::string combine(const xtd::string &path1, const xtd::string &path2)
Combines two path strings.
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:17
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8