xtd 0.2.0
format_pointer.cpp

Show how to use format xtd::format class with memory addresses (pointers).

#include <xtd/console>
#include <xtd/environment>
#include <xtd/string>
using namespace xtd;
auto main() -> int {
auto ptr = static_cast<int*>(nullptr);
console::out << string::format("{}", ptr) << environment::new_line;
ptr = new int(42);
console::out << string::format("0x{:x}", ptr) << environment::new_line;
console::out << string::format("{}", *ptr) << environment::new_line;
delete ptr;
auto sptr = xtd::sptr<int> {};
console::out << string::format("{}", sptr) << environment::new_line;
console::out << string::format("0x{:x}", sptr) << environment::new_line;
console::out << string::format("{}", *sptr) << environment::new_line;
auto uptr = xtd::uptr<int> {};
console::out << string::format("{}", uptr) << environment::new_line;
console::out << string::format("0x{:x}", uptr) << environment::new_line;
console::out << string::format("{}", *uptr) << environment::new_line;
}
// This code can produce the following output :
//
// (null)
// 0x1007380f0
// 42
// (null)
// 0x1053075c8
// 42
// (null)
// 0x1052191a0
// 42
static std::ostream out
Gets the standard output stream. A std::basic_ostream<char_t> that represents the standard output str...
Definition console.hpp:52
static xtd::string new_line() noexcept
Gets the newline string defined for this environment.
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
xtd::unique_ptr_object< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.hpp:25
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
uptr< type_t > new_uptr(args_t &&... args)
xtd::new_uptr operator. This operator creates a xtd::uptr object.
Definition new_uptr.hpp:24
sptr< type_t > new_sptr(args_t &&... args)
xtd::new_sptr operator creates a xtd::sptr object.
Definition new_sptr.hpp:24
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8