Show how to use format xtd::format class with classes.
#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 name_ +
" (" + rank_ +
")";}
friend ostream& operator <<(ostream& os, const character& value) noexcept {return os << value.to_string();}
private:
};
using characters = vector<character>;
auto main()->int {
for (auto c : characters {{"Jean-Luc Picard", "Captain"}, {"William Riker", "Commander"}, {"Data", "Commander"}, {"Beverly Crusher", "Commander"}, {"Geordi La Forge", "Lieutenant Commander"}, {"Worf", "Lieutenant Commander"}, {"Tasha Yar", "Lieutenant"}})
cout << ustring::format("{}", c) << endl;
}
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10