您的位置:首页 > 职场人生

黑马程序员——OC基础之NSLog

2015-12-06 11:59 441 查看
-------
iOS培训、android培训、java培训、期待与您交流! ----------

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {

    @autoreleasepool {

        // insert code here...

        //NSLog和printf使用差异

        //1、NSLog  会自动换行 printf 不会

        //2、NSLog 会自动输出时间等项目信息 printf 不会

        //3、NSLog 参数是一个NSString 对象 printf 是一个字符串常量指针

        NSLog(@"Hello, Black!");

        printf("Hello, Black!\n");

        int a = 5;

        float f1 = 2.3f;

        double d1 = 3.14;

        char ch = 'x';

        char *str = "张三丰";

        printf("%d,%.2f,%.2f,%c\n",a,f1,d1,ch);

        printf("%s\n",str);

        NSLog(@"%d,%.2f,%.2f,%c",a,f1,d1,ch);//可以格式化输出

        NSLog(@"--->%s",str);//写法错误

        //OC用%@输出字符串

        NSString *str1 = @"张三丰";

        NSLog(@"%@",str1);

        //printf("---->%@\n",str1);//不支持

    }

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  NSLog