Xcode 6, Swift - read standard input (console) to

2019-01-26 08:55发布

问题:

I am new to Objective-C and XCode and I'm trying to learn something new. Is there any way to read string from stdin using swift ? Something like cin in C++ ?

回答1:

Just as with Objective-C, you can use NSFileHandle:

let standardInput = NSFileHandle.fileHandleWithStandardInput()
let input = standardInput.availableData


标签: swift xcode6