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

Show how to use xtd::io::file_info::open method.

#include <xtd/xtd>
class program {
public:
static auto main() {
auto path = "MyTest.txt";
auto fi = file_info {path};
// Delete the file if it exists.
if (fi.exists())
fi.remove();
//Create the file.
block_scope_(auto fs = fi.create()) {
auto sw = stream_writer {fs};
sw.write_line("This is some text in the file.");
}
//Open the stream and read it back.
block_scope_(auto fs = fi.open(std::ios::in)) {
auto sr = stream_reader {fs};
while (!sr.end_of_stream())
console::write_line(sr.read_line());
}
}
};
startup_(program::main);
// This code produces the following output :
//
// This is some text in the file.
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:168
#define block_scope_(...)
The specified expression is cleared automatically when the scope is ended.
Definition block_scope.hpp:25