How do I read input from console in swift as 'scanf() in c' and 'input() in python'.
I have tried
var ans = readline()
print(ans)
and its not working
Thanks.
How do I read input from console in swift as 'scanf() in c' and 'input() in python'.
I have tried
var ans = readline()
print(ans)
and its not working
Thanks.
readLine
is the right thing to use. The only possible reason why this does not work is that you're running it in a playground or some other place where the command prompt does not exist.
To make this work, simply create a new command line tool project. Go to "File" -> "New" -> "Project" -> "macOS" -> "Command Line Tool".
Now readLine
should work.