Xcode 6, Swift - read standard input (console) to string [closed]

别来无恙 提交于 2019-12-18 05:54:51

问题


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


来源:https://stackoverflow.com/questions/24046952/xcode-6-swift-read-standard-input-console-to-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!