Writes primitive types in binary to a stream and supports writing strings.
- Inheritance
- xtd::object → 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/xtd>
using namespace std;
class program {
inline static const ustring file_name =
"app_settings.dat";
public:
static void main() {
write_default_values();
display_values();
}
static void write_default_values() {
using_(fstream fs =
file::open(file_name, ios::out | ios::binary | ios::trunc)) {
writer.write(1.250F);
writer.write(R"(c:\Temp)");
writer.write(10);
writer.write(true);
}
}
static void display_values() {
float aspect_ratio;
int auto_save_time;
bool show_status_bar;
aspect_ratio = reader.read_single();
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/xtd>
using namespace std;
class program {
inline static const ustring file_name =
"app_settings.dat";
public:
static void main() {
write_default_values();
display_values();
}
static void write_default_values() {
using_(fstream fs =
file::open(file_name, ios::out | ios::binary | ios::trunc)) {
writer << 1.250F;
writer << R"(c:\Temp)";
writer << 10;
writer << true;
}
}
static void display_values() {
float aspect_ratio;
int auto_save_time;
bool show_status_bar;
reader >> aspect_ratio;
reader >> temp_directory;
reader >> auto_save_time;
reader >> show_status_bar;
}
}
}
};
|
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 (byte_t 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< byte_t, 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< byte_t > &buffer) |
| Writes a byte array to the underlying stream. More...
|
|
virtual void | write (const std::vector< byte_t > &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_t value) |
| Writes a two-byte signed integer to the current stream and advances the stream position by two bytes. More...
|
|
virtual void | write (int32_t value) |
| Writes a four-byte signed integer to the current stream and advances the stream position by four bytes. More...
|
|
virtual void | write (int64_t value) |
| Writes a eight-byte signed integer to the current stream and advances the stream position by eight bytes. More...
|
|
virtual void | write (sbyte_t 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_t value) |
| Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes. More...
|
|
virtual void | write (uint32_t value) |
| Writes a four-byte unsigned integer to the current stream and advances the stream position by four bytes. More...
|
|
virtual void | write (uint64_t 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...
|
|
virtual 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...
|
|
template<typename object_t > |
std::unique_ptr< object_t > | memberwise_clone () const |
| Gets the type of the current instance. 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...
|
|