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

Shows how to use format xtd::parse<bool> method with boolean values.

#include <xtd/console>
#include <xtd/parse>
using namespace xtd;
auto main() -> int {
auto b1 = xtd::parse<bool>("true");
auto b2 = xtd::parse<bool>("false");
auto b3 = xtd::parse<bool>("TRUE");
auto b4 = xtd::parse<bool>("FALSE");
auto b5 = xtd::parse<bool>("1");
auto b6 = xtd::parse<bool>("0");
auto b7 = xtd::parse<bool>(" TrUe ");
auto b8 = xtd::parse<bool>(" fAlSe ");
try {
auto b9 = xtd::parse<bool>("None");
} catch (const system_exception& e) {
console::write_line("Exception : {}", e.message());
}
}
// This code produces the following output :
//
// true
// false
// true
// false
// true
// false
// true
// false
// Exception : Invalid string format
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.hpp:18
bool parse< bool >(const std::string &str)
Convert a string into a type.
Definition parse.hpp:370
@ e
The E key.
Definition console_key.hpp:96
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8