Objective C 2008 中的代码无法编译 [英] Code in Objective C 2008 Does not compile

查看:20
本文介绍了Objective C 2008 中的代码无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过阅读Objective C For Dummies"来学习 Objective-C 的基础知识.我正在使用 XCode 4.4,并且我正在尝试使用一些简单的代码.这个问题之前网上有提过.但是 - 代码似乎无法使用新版本的 XCode 进行编译.

I'm learning the basics of objective-C by Reading 'Objective C For Dummies'. I'm using XCode 4.4, and I'm trying to get some simple code to work. This question has been posed online before. However - the code doesn't seem to compile with the new version of XCode.

问题似乎是 NSLog 这一行(@这是一些很棒的文字!%i",c);这会引发预期表达式"错误.根据之前的表单发布,我在首选项中禁用了自动参考检查,但仍然失败.

At issue seems to be the line NSLog (@"Here is some amazing text! %i",c); This throws an 'Expected Expression' Error. Per the previous form posting, I have disabled automatic reference checking in preferences and this still fails.

#include <stdio.h>

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

    //declare variables
    int a;
    int b;
    int c;

    //set the variables
    a = 2;
    b = 3;

    //Perform the computations
    c = a % b;

    //Output the results
    NSLog (@"Here is some amazing text! %c",c);

    return 0;
}

推荐答案

在顶部添加#import ,并更改NSLog对此:

Add #import <Foundation/Foundation.h> at the top, and change the NSLog to this:

NSLog (@"Here is some amazing text! %d",c);

因为%c 并不意味着一个名为c 的变量",而是一个char.%d 表示int,也就是c.

Because %c doesn't mean "a variable called c", but rather a char. %d means an int, which is what c is.

这篇关于Objective C 2008 中的代码无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆