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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 那个Mr_Z 中级黑马   /  2014-4-17 11:39  /  1204 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

#import <Foundation/Foundation.h>

typedef enum{
    SexMan,
    SexWomen

  }Sex;

  typedef struct
  {
     int year;

     int month;
     int day;
  }Date;

@interface Student:NSObject
{       @public
        Sex sex;
        double weight;
        Date birthday;
        char *name;

}
-(void)eat;
-(void)run;

@end
@implementation Student
-(void)eat
{
    weight +=1;
    NSLog(@"现在是%d斤",weight);

}
-(void)run
{
    weight -=1;
    NSLog(@"现在是%d斤",weight);

}
@end
int main()
{
        Student *p = [Student new];
        p->weight=50;
        p ->sex =SexMan;
        p->birthday.year =2011;
        p->birthday.month = 12;
        p ->birthday.day = 16;
        [p run];
        [p eat];
        return 0;

}
报错原因:Codeponit out of the rage of the constant string
我想问下,我是在Codeblock里编译的,这个错误是什么意思?

评分

参与人数 1黑马币 +2 收起 理由
jing迪 + 2

查看全部评分

4 个回复

倒序浏览
  1. @implementation Student
  2. -(void)eat
  3. {
  4.     weight +=1;
  5.     NSLog(@"现在是%d斤",weight);

  6. }
  7. -(void)run
  8. {
  9.     weight -=1;
  10.     NSLog(@"现在是%d斤",weight); // %d改为%f看看,别的找不到有错误的了。我在xcode上没问题

  11. }
复制代码

评分

参与人数 1黑马币 +2 收起 理由
jing迪 + 2

查看全部评分

回复 使用道具 举报
我也没看出来什么问题。。。
回复 使用道具 举报
本帖最后由 conpgy 于 2014-4-17 14:55 编辑

除了上面提示的改为%f外。这里错误提示的意思大概意思是编码格式超出字符串的范围。就是NSLog里面不支持中文。这段代码是没有错的,Xcode是没有问题的。那就是window环境或者是编译器对中文格式的问题了。

评分

参与人数 1黑马币 +2 收起 理由
jing迪 + 2

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马