How to read input from the keyboard in Objective-C

前端 未结 3 1137
余生分开走
余生分开走 2021-01-15 16:27

Hi I am making a program that gets input from the keyboard and I was wondering if there was any way to get input from the keyboard and store it in an NSString o

3条回答
  •  余生分开走
    2021-01-15 16:48

    Why not this?

    NSFileHandle *kbd = [NSFileHandle fileHandleWithStandardInput];
    NSData *inputData = [kbd availableData];
    NSString *option = [[NSString alloc] initWithData:inputData encoding:NSUTF8StringEncoding];
    

提交回复
热议问题