xtd 0.2.0
Loading...
Searching...
No Matches
xtd::istringable Class Referenceabstract
Inheritance diagram for xtd::istringable:
xtd::interface

Definition

Provides a way to represent the current object as a string.

Namespace
xtd
Library
xtd.core
Examples
The following exemple shows how to use xtd::istringable interface.
#include <xtd/console>
#include <xtd/environment>
#include <xtd/istringable>
using namespace xtd;
class character : public istringable {
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 override {return name_ + " (" + rank_ + ")";}
private:
string name_;
string rank_;
};
using characters = std::initializer_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"}})
}
// 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)
static std::ostream out
Gets the standard output stream. A std::basic_ostream<char_t> that represents the standard output str...
Definition console.h:52
static xtd::string new_line() noexcept
Gets the newline string defined for this environment.
Provides a way to represent the current object as a string.
Definition istringable.h:23
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition to_string.h:41
@ c
The C key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Remarks
Types inheriting from xtd::object should not implement the xtd::istringable interface. For more info, see xtd::object::to_string Method.
Examples
interface.cpp, and interface2.cpp.

Public Methods

virtual xtd::string to_string () const =0
 Gets a string that represents the current object.
 

Member Function Documentation

◆ to_string()

virtual xtd::string xtd::istringable::to_string ( ) const
pure virtual

Gets a string that represents the current object.

Returns
A string that represents the current object.

The documentation for this class was generated from the following file: