Writes primitive types in binary to a stream and supports writing strings.
- Inheritance
- xtd::object → xtd::io::binary_writer
- Header
#include <xtd/io/binary_writer>
- Namespace
- xtd::io
- Library
- xtd.core
- Examples
- The following code example demonstrates how to store and retrieve application settings in a file.
#include <xtd/io/binary_reader>
#include <xtd/io/binary_writer>
#include <xtd/io/file>
#include <xtd/console>
#include <xtd/startup>
#include <xtd/using>
using namespace std;
class program {
inline static const ustring file_name =
"app_settings.dat";
public:
static auto main() {
write_default_values();
display_values();
}
static void write_default_values() {
writer.write(R"(c:\Temp)");
writer.write(10);
writer.write(true);
}
}
static void display_values() {
auto aspect_ratio = .0f;
auto auto_save_time = 0;
auto show_status_bar = false;
temp_directory = reader.read_string();
auto_save_time = reader.read_int32();
show_status_bar = reader.read_boolean();
}
}
}
};
- Examples
- The same example with stream operators.
#include <xtd/io/binary_reader>
#include <xtd/io/binary_writer>
#include <xtd/io/file>
#include <xtd/console>
#include <xtd/startup>
#include <xtd/using>
using namespace std;
class program {
inline static const ustring file_name =
"app_settings.dat";
public:
static auto main() {
write_default_values();
display_values();
}
static void write_default_values() {
writer << 1.250F;
writer << R"(c:\Temp)";
writer << 10;
writer << true;
}
}
static void display_values() {
auto aspect_ratio = .0f;
auto auto_save_time = 0;
auto show_status_bar = false;
reader >> aspect_ratio;
reader >> temp_directory;
reader >> auto_save_time;
reader >> show_status_bar;
}
}
}
};
- Examples:
- binary_reader.cpp, binary_reader2.cpp, and binary_reader3.cpp.
|
virtual void | close () |
| Closes the xtd::io::binary_writer object and the underlying stream, and releases any system resources associated with the reader. More...
|
|
virtual void | flush () |
| Clears all buffers for the current writer and causes any buffered data to be written to the underlying device. More...
|
|
virtual size_t | seek (size_t offset, std::ios::seekdir origin) |
| Sets the position within the current stream. More...
|
|
virtual void | write (bool value) |
| Writes a one-byte boolean value to the current stream, with 0 representing false and 1 representing true. More...
|
|
virtual void | write (xtd::byte value) |
| Writes an unsigned byte to the current stream and advances the stream position by one byte. More...
|
|
virtual void | write (char value) |
| Writes a character to the current stream and advances the current position by one byte. More...
|
|
template<size_t size> |
void | write (const std::array< xtd::byte, size > &buffer) |
| Writes a byte array to the underlying stream. More...
|
|
template<size_t size> |
void | write (const std::array< char, size > &buffer) |
| Writes a character array to the underlying stream. More...
|
|
virtual void | write (const std::vector< xtd::byte > &buffer) |
| Writes a byte array to the underlying stream. More...
|
|
virtual void | write (const std::vector< xtd::byte > &buffer, size_t index, size_t count) |
| Writes a region of a byte array to the current stream. More...
|
|
virtual void | write (const std::vector< char > &buffer) |
| Writes a character array to the underlying stream. More...
|
|
virtual void | write (const std::vector< char > &buffer, size_t index, size_t count) |
| Writes a region of a character array to the current stream. More...
|
|
virtual void | write (double value) |
| Writes an eight-byte floating-point value to the current stream and advances the stream position by eight bytes. More...
|
|
virtual void | write (int16 value) |
| Writes a two-byte signed integer to the current stream and advances the stream position by two bytes. More...
|
|
virtual void | write (int32 value) |
| Writes a four-byte signed integer to the current stream and advances the stream position by four bytes. More...
|
|
virtual void | write (int64 value) |
| Writes a eight-byte signed integer to the current stream and advances the stream position by eight bytes. More...
|
|
virtual void | write (sbyte value) |
| Writes an signed byte to the current stream and advances the stream position by one byte. More...
|
|
virtual void | write (float value) |
| Writes an four-byte floating-point value to the current stream and advances the stream position by four bytes. More...
|
|
virtual void | write (const ustring &value) |
| Writes a length-prefixed string to this stream, and advances the current position of the stream and the specific characters being written to the stream. More...
|
|
virtual void | write (uint16 value) |
| Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes. More...
|
|
virtual void | write (uint32 value) |
| Writes a four-byte unsigned integer to the current stream and advances the stream position by four bytes. More...
|
|
virtual void | write (uint64 value) |
| Writes a eight-byte unsigned integer to the current stream and advances the stream position by eight bytes. More...
|
|
|
| object ()=default |
| Create a new instance of the ultimate base class object. More...
|
|
bool | equals (const object &obj) const noexcept |
| Determines whether the specified object is equal to the current object. More...
|
|
virtual size_t | get_hash_code () const noexcept |
| Serves as a hash function for a particular type. More...
|
|
virtual type_object | get_type () const noexcept |
| Gets the type of the current instance. More...
|
|
template<typename object_t > |
std::unique_ptr< object_t > | memberwise_clone () const noexcept |
| Creates a shallow copy of the current object. More...
|
|
virtual xtd::ustring | to_string () const noexcept |
| Returns a sxd::ustring that represents the current object. More...
|
|
static bool | equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are considered equal. More...
|
|
static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are the same instance. More...
|
|