Categories
objective-c

objective-c 标准流

objective-c 没有定义自己标准输入流 输出流 异常流

需要依赖C语言的stdio

objective-c 可以完美运行C语言代码(惊呆了)

#import <Foundation/Foundation.h>
#include <stdio.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        char name[100];
        NSLog(@"Please enter the name you wish to search for ");
        scanf("%s", name);
        printf("name : %s\n",name);

        //NSString *name2 = [NSString stringWithFormat:@"%s" , name];
        NSString *name2 = [NSString stringWithCString:name encoding:NSUTF8StringEncoding]; //转化 char[] 为NSString
        NSLog(@"name2 : %@" , name2);
        
        fprintf(stdout,"abc123\n");//标准输出流输出
        fprintf(stderr,"abc123\n");//标准异常流输出
    
    }
    return 0;
}

Leave a Reply