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

Shows how to use xtd::iformatable interface.

#include <xtd/console>
#include <xtd/environment>
#include <xtd/iformatable>
using namespace xtd;
class foo : public object, public iformatable {
public:
explicit foo(int value) : value_ {value} {}
using object::to_string;
string to_string(const string& format, const std::locale& loc) const override {return string::format(string::format("{{:{}}}", format), value_);}
private:
int value_ = 0;
};
auto main() -> int {
auto f = foo {42};
console::out << "standard output :" << environment::new_line;
console::out << " " << f << environment::new_line;
console::out << " " << f.to_string() << environment::new_line;
console::out << string::format(" {}", f) << environment::new_line;
console::out << string::format(" 0b{:b8}", f) << environment::new_line;
console::out << " 0b" << f.to_string("b8", std::locale {}) << environment::new_line;
console::write_line();
console::write_line("write_line :");
console::write(" ");
console::write_line(f);
console::write(" ");
console::write_line(f.to_string());
console::write_line(" {}", f);
console::write_line(" 0b{:b8}", f);
console::write(" 0b");
console::write_line(f.to_string("b8", std::locale {}));
}
// This code produces the following output :
//
// standard output :
// 42
// 42
// 42
// 0b00101010
// 0b00101010
//
// write_line :
// 42
// 42
// 42
// 0b00101010
// 0b00101010
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:35
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
@ f
The F key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10