A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© niujiayue 中级黑马   /  2015-11-2 00:11  /  876 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        int num = 10;
        float f1 = 3.14f;
        char ch ='Q';
        char *s = "叶良辰";
        NSString *str = @"赵日天";  //OC的字符串
        //OC中的NSLog 函数
        //1) 可以自动换行
        //2) 多了时间戳
        //3) 多了项目的名称
        //4) 头文件 ObjcRuntime.h
        // 注意: NSLog 不能打印 C的中文字符串
        NSLog(@"Hello, World! num = %d,f1 = %.2f,ch = %c,s = %s",num,f1,ch,s);
        
        //C中得输出函数
        //1) 不能自动换行
        //2) 不能输出时间戳信息
        //3) stdio.h
        // printf能输出OC的字符串吗? 不能
        printf("Hello, World! num = %d,f1 = %.2f,ch = %c,s = %s,str = %s\n",num,f1,ch,s,str);
    }
    return 0;
}

2 个回复

倒序浏览
toveyloves 来自手机 中级黑马 2015-11-2 00:27:34
沙发
为什么printf能输出OC的字符串?
回复 使用道具 举报
toveyloves 发表于 2015-11-2 00:27
为什么printf能输出OC的字符串?

都 一样好吧,OC是在C的基本上再扩展的
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马