Objective-C:如何进行控制台输入? [英] Objective-C: How do I do console input?
本文介绍了Objective-C:如何进行控制台输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从控制台输入获取 NSString,然后尝试将其转换为 int?
How do I get an NSString from console input, and then try to cast it into an int?
推荐答案
您可以从控制台(scanf 或其他)读取 char*
字符串,就像在常规 C 程序中一样.然后,使用 stringFromCString:withEncoding:
从中创建一个 NSString
对象.最后,使用NSString
的integerValue
函数来获取它的数值.
You can read in a char*
string from console (scanf or whatever), like you would in a regular C program. Then, create an NSString
object from it using stringFromCString:withEncoding:
. Finally, use NSString
's integerValue
function to get it's numerical value.
这篇关于Objective-C:如何进行控制台输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文