xtd 0.2.0
main.cpp

Shows how to use xtd::startup class.

#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
namespace main_example {
class program {
public:
static auto main(const argument_collection& args) {
auto number = 0;
if (args.size() != 1 || try_parse(args[0], number) == false || number < 0 || number > 20) {
console::write_line("Please enter an integer argument betwween 0 and 20.");
console::write_line("Usage: factorial <integer>");
return -1;
}
console::write_line("The factorial of {} is {}", number, [&] {
auto result = 1l;
for (auto i = 1; i <= number; ++i)
result *= i;
return result;
}());
return 0;
}
};
}
startup_(main_example::program::main);
// This code produces the following output if 3 is entered on command line:
//
// The factorial of 3 is 6.
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::array::begin(),...
Definition basic_array.hpp:246
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:168
xtd::array< xtd::string > argument_collection
Represents the collection of arguments passed to the main entry point method.
Definition argument_collection.hpp:19
bool try_parse(const std::basic_string< char > &str, value_t &value) noexcept
Convert a string into a type.
Definition parse.hpp:416
@ number
Indicates that the allow_leading_white, allow_trailing_white, allow_leading_sign, allow_trailing_sign...
Definition number_styles.hpp:46
@ i
The I key.
Definition console_key.hpp:104
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8