Show how to use format xtd::format class.
#include <xtd/format_exception>
#include <xtd/ustring>
using namespace std;
class character {
public:
character(
const ustring& name,
const ustring& rank) noexcept : name_(name), rank_(rank) {}
const ustring& name()
const noexcept {
return name_;}
const ustring& rank()
const noexcept {
return rank_;}
ustring to_string()
const noexcept {
return to_string(
"F");}
if (fmt == "F") return name_ + " (" + rank_ + ")";
if (fmt == "N") return name_;
if (fmt == "R") return rank_;
}
private:
};
template<>
string xtd::to_string(
const character& value,
const string& fmt,
const locale& loc) {
return value.to_string(fmt);}
using characters = vector<character>;
auto main()->int {
cout << ustring::sprintf(
"%s",
c.to_string()) << endl;
cout << ustring::sprintf(
"%s",
c.to_string(
"F")) << endl;
cout << ustring::sprintf(
"%s",
c.to_string(
"N")) << endl;
cout << ustring::sprintf(
"%s",
c.to_string(
"R")) << endl;
}
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
#define current_stack_frame_
Provides information about the current stack frame.
Definition current_stack_frame.h:16
@ character
Specifies that the text is trimmed to the nearest character.
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition date_time.h:1080
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10