How to use "read_bool"?

Timon Gehr timon.gehr at gmx.ch
Thu Aug 2 21:33:24 PDT 2012


On 08/03/2012 06:17 AM, 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:
>
> import std.stdio;
> import std.conv;
> import std.string;
>
> void main()
> {
> write("How many are we? ");
> int personCount;
> readf(" %s", &personCount);
>
> write("How many bicycles are there? ");
> int bicycleCount;
> readf(" %s", &bicycleCount);
>
> write("What is the distance to the beach? ");
> int distance;
> readf(" %s", &distance);
>
> bool existsCar = read_bool("Is there a car? ");
> bool existsLicense =
> read_bool("Is there a driver license? ");
>
> When i try compile this, i get the following errors:
>
> hello.d|43|Error: undefined identifier read_bool|
> hello.d|44|Error: undefined identifier read_bool|
> ||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===|
>
> So, someone know what's happening? What is the correct way to use the
> Read_bool?
>
> Thanks for everyone!
>

presumably read_bool is part of the tutorial. Otherwise you may use this:

bool read_bool(){
     auto str = readln()[0..$-1];
     switch(str){
         case "true", "y", "ye", "yes": return true;
         case "false", "n", "no": return false;
         default: throw new Exception("please answer yes or no");
     }
}




More information about the Digitalmars-d-learn mailing list