#include <xtd/io/binary_reader>
#include <xtd/io/binary_writer>
#include <xtd/io/file>
#include <xtd/block_scope>
#include <xtd/console>
#include <xtd/startup>
class program {
inline static const string file_name = "app_settings.dat";
public:
static auto main() {
write_default_values();
display_values();
}
static void write_default_values() {
block_scope_(
auto fs = file::open(file_name, std::ios::out | std::ios::binary | std::ios::trunc)) {
writer << 1.250F;
writer << R"(c:\Temp)";
writer << 10;
writer << true;
}
}
static void display_values() {
auto aspect_ratio = .0f;
auto temp_directory = string::empty_string;
auto auto_save_time = 0;
auto show_status_bar = false;
if (file::exists(file_name)) {
block_scope_(
auto fs = file::open(file_name, std::ios::in | std::ios::binary)) {
reader >> aspect_ratio;
reader >> temp_directory;
reader >> auto_save_time;
reader >> show_status_bar;
}
console::write_line("Aspect ratio set to: {}", aspect_ratio);
console::write_line("Temp directory is: {}", temp_directory);
console::write_line("Auto save time set to: {}", auto_save_time);
console::write_line("Show status bar: {}", show_status_bar);
}
}
};
Reads primitive data types as binary values in a specific encoding.
Definition binary_reader.hpp:40
Writes primitive types in binary to a stream and supports writing strings.
Definition binary_writer.hpp:42
#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:175
#define block_scope_(...)
The specified expression is cleared automatically when the scope is ended.
Definition block_scope.hpp:25
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