How to use "read_bool"?
Ali Çehreli
acehreli at yahoo.com
Thu Aug 2 23:05:46 PDT 2012
On 08/02/2012 09:17 PM, Zeh wrote:
> Hi, i am just a newbie trying learn D. But, i get having some trouble
> with "read_bool". More specifically on program of this lesson:
As Timon said, read_bool() is a separate function on the same page, a
little after main():
bool read_bool(string message)
{
// Print the message
writef(message ~ "(false or true) ");
// Read the line as a string
string input;
while (input.length == 0) {
input = chomp(readln());
}
// Produce a 'bool' value from that string
bool result = to!bool(input);
// Return the result to the caller
return result;
}
Unlike Timon's function, you must enter either "false" or "true" with
the one above.
Ali
More information about the Digitalmars-d-learn
mailing list