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

Show how to use format xtd::format class with class objects.

#include <xtd/collections/generic/list>
#include <xtd/console>
#include <xtd/environment>
#include <xtd/format>
using namespace xtd;
using namespace xtd::collections::generic;
class character : public object {
public:
character() = default;
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 override {return name_ + " (" + rank_ + ")";}
private:
string name_;
string rank_;
};
using characters = list<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"}})
console::out << format("{}", c) << environment::new_line;
}
// This code produces the following output :
//
// Jean-Luc Picard (Captain)
// William Riker (Commander)
// Data (Commander)
// Beverly Crusher (Commander)
// Geordi La Forge (Lieutenant Commander)
// Worf (Lieutenant Commander)
// Tasha Yar (Lieutenant)
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:71
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
xtd::string format(const xtd::string &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:20
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:15
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10