HaxeFoundation / haxe.org-comments

Repository to collect comments of our haxe.org websites
2 stars 2 forks source link

[code.haxe.org] Beginner - stdin, stdout, stderr #97

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

stdin, stdout, stderr - Beginner - Haxe programming language cookbook

Reading from stdin and writing to stdout and stderr.

https://code.haxe.org/category/beginner/stdin-stdout-stderr.html

chikega commented 2 years ago

Basic IO demonstrating receiving and converting/casting various data-type inputs from the user:


class BasicIOTest {

    static function main()
    {
            Sys.print("What is your name? ");
            var name = Sys.stdin().readLine();
            Sys.println('It\'s nice to meet you $name!');
            Sys.print("How old are you? ");
            var age = Std.parseInt(Sys.stdin().readLine());
            Sys.print("What is your GPA? ");
            var gpa = Std.parseFloat(Sys.stdin().readLine());
            Sys.println('So $name, you are $age years old and your GPA is $gpa ... stellar!');

    }

}