枚举应该以什么格式打印? %什么?

发布于 2024-12-17 07:20:48 字数 349 浏览 2 评论 0原文

这行代码导致编译器报错并进入调试模式

NSLog(@"Attacker card: %@", [attackerCard suit]);

我想知道这是否是由于西装是一个enum值声明为

@property (assign) Suit suit;

其中Suit被声明为

typedef enum {
    CLUBS, DIAMONDS, HEARTS, SPADES
} Suit;

Am我的格式有问题,或者问题出在其他地方?

This line of code causes compiler to complain and enter a debug mode

NSLog(@"Attacker card: %@", [attackerCard suit]);

I wonder whether it is due to the fact that suit is an enum value declared as

@property (assign) Suit suit;

Where Suit is declared as

typedef enum {
    CLUBS, DIAMONDS, HEARTS, SPADES
} Suit;

Am i doing something wrong with the format or, the problem lies elsewhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇柔作态 2024-12-24 07:20:48

枚举类型的具体大小是实现定义的,但它始终是整数类型,因此 %d 在大多数情况下都可以工作。如果您需要它非常强大,您需要测试 sizeof(Suit) 并基于此选择一种格式。

The specific size of an enumerated type is implementation defined but it's always an integer type, so %d will work most of the time. If you need it to be very robust, you'll want to test sizeof(Suit) and choose a format based on that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文