#include <xtd/format_exception>
#include <xtd/console>
#include <xtd/environment>
#include <xtd/string>
public:
character(const string& name, const string& rank) noexcept : name_(name), rank_(rank) {}
const string& name() const noexcept {return name_;}
const string& rank() const noexcept {return rank_;}
string to_string() const noexcept {return to_string("", std::locale {});}
string to_string(const string& format, const std::locale& loc) const override {
auto fmt = string::is_empty(format) ? "F" : format;
if (fmt == "F") return name_ + " (" + rank_ + ")";
if (fmt == "N") return name_;
if (fmt == "R") return rank_;
}
private:
string name_;
string rank_;
};
auto main() -> int {
auto c = character {"Jean-Luc Picard", "Captain"};
console::out << string::format("{}", c) << environment::new_line;
console::out << string::format("{:F}", c) << environment::new_line;
console::out << string::format("{:N}", c) << environment::new_line;
console::out << string::format("{:R}", c) << environment::new_line;
}
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10