tags:

views:

2517

answers:

2

How do I get an NSString from console input, and then try to cast it into an int?

+3  A: 

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.

codelogic
+2  A: 

You can also do it directly with scanf. Example

int number = 0;
scanf("%d", &number);