xtd 0.2.0
Loading...
Searching...
No Matches

◆ read()

static int32 xtd::console::read ( )
static

Reads the next character from the standard input stream.

Returns
int32 The next character from the input stream, or negative one (-1) if there are currently no more characters to be read
Remarks
The Read method blocks its return while you type input characters; it terminates when you press the Enter key.
Pressing Enter appends a platform-dependent line termination sequence to your input (for example, Windows appends a carriage return-linefeed sequence).
Subsequent calls to the Read method retrieve your input one character at a time. After the final character is retrieved, Read blocks its return again and the cycle repeats.
Note that you will not get a property value of -1 unless you perform one of the following actions: simultaneously press the Control modifier key and Z console key (CTRL+Z),
which signals the end-of-file condition; press an equivalent key that signals the end-of-file condition, such as the F6 function key in Windows; or redirect the input stream to a source,
such as a text file, that has an actual end-of-file character.
Example
The following example demonstrates the Read method.
#include <xtd/char_object>
#include <xtd/console>
#include <xtd/convert>
using namespace xtd;
auto main() -> int {
auto m1 = "\nType a string of text then press Enter. "
"Type '+' anywhere in the text to quit:\n";
auto m2 = "Character '{0}' is hexadecimal 0x{1:x4}.";
auto m3 = "Character is hexadecimal 0x{0:x4}.";
auto ch = U'0';
//
do {
auto x = console::read();
try {
if (ch == 0x0a)
} else
} catch (const overflow_exception& e) {
console::write_line("{0} Value read = {1}.", e.message(), x);
}
} while (ch != '+');
}
// This code produces the following output :
//
// Type a string of text then press Enter. Type '+' anywhere in the text to quit:
//
// The quick brown fox.
// Character 'T' is hexadecimal 0x0054.
// Character 'h' is hexadecimal 0x0068.
// Character 'e' is hexadecimal 0x0065.
// Character is hexadecimal 0x0020.
// Character 'q' is hexadecimal 0x0071.
// Character 'u' is hexadecimal 0x0075.
// Character 'i' is hexadecimal 0x0069.
// Character 'c' is hexadecimal 0x0063.
// Character 'k' is hexadecimal 0x006b.
// Character is hexadecimal 0x0020.
// Character 'b' is hexadecimal 0x0062.
// Character 'r' is hexadecimal 0x0072.
// Character 'o' is hexadecimal 0x006f.
// Character 'w' is hexadecimal 0x0077.
// Character 'n' is hexadecimal 0x006e.
// Character is hexadecimal 0x0020.
// Character 'f' is hexadecimal 0x0066.
// Character 'o' is hexadecimal 0x006f.
// Character 'x' is hexadecimal 0x0078.
// Character '.' is hexadecimal 0x002e.
// Character is hexadecimal 0x000d.
// Character is hexadecimal 0x000a.
//
// Type a string of text then press Enter. Type '+' anywhere in the text to quit:
//
// ^Z
// Value was either too large or too small for a character. Value read = -1.
//
// Type a string of text then press Enter. Type '+' anywhere in the text to quit:
//
// +
// Character '+' is hexadecimal 0x002b.
static bool is_white_space(type_t c) noexcept
Indicates whether the specified Unicode character is categorized as white space.
Definition box_char.h:187
static constexpr type_t min_value
Represents the smallest possible value of type_t. This field is constant.
Definition box_integer.h:70
static int32 read()
Reads the next character from the standard input stream.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static char32 to_char32(std::any value)
Convert std::any to char32.
The exception that is thrown when an arithmetic, casting, or conversion operation in a checked contex...
Definition overflow_exception.h:18
@ x
The X key.
@ e
The E key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10