linux bool变量,Objective-C中的占位符,打印BOOL类型数据

常用的一些占位符:

%@:字符串占位符

%d:整型

%ld:长整型

%f:浮点型

%c:char类型

%%:%的占位符

尽管有那么多的占位符,但是好像没有发现BOOL型的数据的占位符,这也是比较纠结的地方,看了一下别人是怎么解决这个问题的

BOOL studyBool = YES;

NSLog(@"打印BOOL型数据%@",studyBool?@"YES":@"NO");//打印BOOL型数据YES

NSLog(@"打印BOOL型数据%d",studyBool);//打印BOOL型数据1

BOOL alsoBool = NO;

NSLog(@"打印BOOL型数据%@",alsoBool?@"YES":@"NO");//打印BOOL型数据NO

NSLog(@"打印BOOL型数据%d",alsoBool);//打印BOOL型数据0

详细介绍:**********************************************************

%@:            Objective-C对象,印有字符串返回descriptionWithLocale:如果于的话,或描述相反.CFTypeRef工作对象,返回的结果的CFCopyDescription功能.(这个翻译有问题建议按照自己的理解方式理解)。

%%:            为'%'字符;

%d,%D,%i:  为32位整型数(int);

%u,%U:        为32位无符号整型数(unsigned int);

%hi:  为有符号的16位整型数(short);

%hu:  为无符号的16位整型数(unsigned shord);

%qi:  为有符号的64位整型数(long long);

%qu:  为无符号的64位整型数(unsigned long long);

%x:    为32位的无符号整型数(unsigned int),打印使用数字0-9的十六进制,小写a-f;

%X:    为32位的无符号整型数(unsigned int),打印使用数字0-9的十六进制,大写A-F;

%qx:  为无符号64位整数(unsigned long long),打印使用数字0-9的十六进制,小写a-f;

%qX:  为无符号64位整数(unsigned long long),打印使用数字0-9的十六进制,大写A-F;

%o,%O:  为32位的无符号整数(unsigned int),打印八进制数;

%f:      为64位的浮点数(double);

%e:      为64位的浮点数(double),打印使用小写字母e,科学计数法介绍了指数的增大而减小;

%E:      为64位的浮点数(double),打印科学符号使用一个大写E介绍指数的增大而减小;

%g:      为64位的浮点数(double),用%e的方式打印指数,如果指数小于4或者大于等于精度,那么%f的风格就会有不同体现;

%G:      为64位的浮点数(double),用%E的方式打印指数,如果指数小于4或者大于等于精度,那么%f的风格就会有不同体现;

%c:      为8位的无符号字符%c(unsigned char),通过打印NSLog()将其作为一个ASCII字符,或者,不是一个ASCII字符,八进制格式\ddd或统一标准的字符编码的十六进制格式\udddd,在这里d是一个数字;

%C:      为16位Unicode字符%C(unichar),通过打印NSLog()将其作为一个ASCII字符,或者,不是一个ASCII字符,八进制格式\ddd或统一标准的字符编码的十六进制格式\\udddd,在这里d是一个数字;

%s:      对于无符号字符数组空终止,%s系统中解释其输入编码,而不是别的,如utf-8;

%S:      空终止一系列的16位Unicode字符;

%p:      空指针(无效*),打印十六进制的数字0-9和小写a-f,前缀为0x;

%L:      在明确规定的长度下,进行修正,下面的一批数据a,A,e,E,f,F,g,G应用于双精度长整型的参数;

%a:      为64位的浮点数(double),按照科学计数法打印采用0x和一个十六进制数字前使用小写小数点p来介绍指数的增大而减小;

%A:      为64位的浮点数(double),按照科学计数法打印采用0X和一个十六进制数字前使用大写字母小数点P界扫指数的增大而减小;

%F:      为64位的浮点数(double),按照十进制表示法进行打印;

%z:      修改说明在%z长度以下d,i,o,u,x,X适用于某一指定类型的转换或者适用于一定尺寸的整数类型的参数;

%t:      修改说明在%t长度以下d,i,o,u,x,X适用于某一指定类型或一定尺寸的整数类型的转换的参数;

%j:      修改说明在%j长度以下d,i,o,u,x,X适用于某一指定类型或一定尺寸的整数类型的转换的参数。

英文文档

格式定义

The format specifiers supported by the NSString formatting methods and CFString formatting functions follow the IEEE printf specification; the specifiers are summarized in Table 1. Note that you can also use the “n$” positional specifiers such as %1$@ %2$s. For more details, see the IEEE printf specification. You can also use these format specifiers with the NSLog function.

Table 1 Format specifiers supported by the NSString formatting methods and CFString formatting functions

定义

说明

%@

Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function.

%%

‘%’ character

%d, %D, %i

Signed 32-bit integer (int)

%u, %U

Unsigned 32-bit integer (unsigned int)

%hi

Signed 16-bit integer (short)

%hu

Unsigned 16-bit integer (unsigned short)

%qi

Signed 64-bit integer (long long)

%qu

Unsigned 64-bit integer (unsigned long long)

%x

Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and lowercase a–f

%X

Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and uppercase A–F

%qx

Unsigned 64-bit integer (unsigned long long), printed in hexadecimal using the digits 0–9 and lowercase a–f

%qX

Unsigned 64-bit integer (unsigned long long), printed in hexadecimal using the digits 0–9 and uppercase A–F

%o, %O

Unsigned 32-bit integer (unsigned int), printed in octal

%f

64-bit floating-point number (double)

%e

64-bit floating-point number (double), printed in scientific notation using a lowercase e to introduce the exponent

%E

64-bit floating-point number (double), printed in scientific notation using an uppercase E to introduce the exponent

%g

64-bit floating-point number (double), printed in the style of %e if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise

%G

64-bit floating-point number (double), printed in the style of %E if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise

%c

8-bit unsigned character (unsigned char), printed by NSLog() as an ASCII character, or, if not an ASCII character, in the octal format \\ddd or the Unicode hexadecimal format \\udddd, where d is a digit

%C

16-bit Unicode character (unichar), printed by NSLog() as an ASCII character, or, if not an ASCII character, in the octal format \\ddd or the Unicode hexadecimal format \\udddd, where d is a digit

%s

Null-terminated array of 8-bit unsigned characters. %s interprets its input in the system encoding rather than, for example, UTF-8.

%S

Null-terminated array of 16-bit Unicode characters

%p

Void pointer (void *), printed in hexadecimal with the digits 0–9 and lowercase a–f, with a leading 0x

%L

Length modifier specifying that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument

%a

64-bit floating-point number (double), printed in scientific notation with a leading 0x and one hexadecimal digit before the decimal point using a lowercase p to introduce the exponent

%A

64-bit floating-point number (double), printed in scientific notation with a leading 0X and one hexadecimal digit before the decimal point using a uppercase P to introduce the exponent

%F

64-bit floating-point number (double), printed in decimal notation

%z

Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument

%t

Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a ptrdiff_t or the corresponding unsigned integer type argument

%j

Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a intmax_t or uintmax_t argument

平台依赖

Mac OS X uses several data types—NSInteger, NSUInteger,CGFloat, and CFIndex—to provide a consistent means of representing values in 32- and 64-bit environments. In a 32-bit environment, NSInteger and NSUInteger are defined as int and unsigned int, respectively. In 64-bit environments, NSInteger and NSUInteger are defined as long and unsigned long, respectively. To avoid the need to use different printf-style type specifiers depending on the platform, you can use the specifiers shown in Table 2. Note that in some cases you may have to cast the value.

Table 2 Format specifiers for data types

类型

定义

建议

NSInteger

%ld or %lx

Cast the value to long

NSUInteger

%lu or %lx

Cast the value to unsigned long

CGFloat

%f or %g

%f works for floats and doubles when formatting; but see below warning when scanning

CFIndex

%ld or %lx

The same as NSInteger

pointer

%p

%p adds 0x to the beginning of the output. If you don’t want that, use %lx and cast to long.

long long

%lld or %llx

long long is 64-bit on both 32- and 64-bit platforms

unsigned long long

%llu or %llx

unsigned long long is 64-bit on both 32- and 64-bit platforms

The following example illustrates the use of %ld to format an NSInteger and the use of a cast.

1

2

NSInteger i = 42;

printf("%ld\n", (long)i);

In addition to the considerations mentioned in Table 2, there is one extra case with scanning: you must distinguish the types for float and double. You should use %f for float, %lf for double. If you need to use scanf (or a variant thereof) with CGFloat, switch to double instead, and copy the double to CGFloat.

1

2

3

4

CGFloat imageWidth;

double tmp;

sscanf (str, "%lf", &tmp);

imageWidth =tmp;

It is important to remember that %lf does not represent CGFloat correctly on either 32- or 64-bit platforms. This is unlike %ld, which works for long in all cases.0b1331709591d260c1c78e86d0c51c18.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/566413.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

函数在c语言中的地位和作用,C语言重要考点分析

C语言重要考点分析有人说:好好学习,天天向上,的确,我们是应该这么做,作为一个中小学生的感受来理解学习,我们大概都认为学习不好玩,读书的都是书呆子,但是等到知道学习能干什么时&am…

c语言简单选择对字符串数组排序,简单了解C语言中直接插入排序与直接选择排序实现...

直接插入排序基本思路:1. 从a[0]开始,也就是从1个元素开始是有序的,a[1]~a[n-1]是无序的。2. 从a[1]开始并入前面有序的数组,直到n-1。#include #define N 5void insertsort(int a[], int n);void swap(int *x, int *y);void inse…

c语言逆波兰计算器程序,C语言实现的简单的逆波兰计算器

前后调试了好几天,类型转换问题颇为麻烦,无赖使用两种不同类型的栈解决,但程序目前还有两个问题:1.目前不能进行float类型的计算;2.不能进行多位数的运算。实际上就是目前只能进行个位数的带括号的加减乘除运算&#x…

c语言竞赛成绩排序,吧内编程竞赛:成绩公布

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼第二第三题太狡猾了第二题居然有重复的路……怪不得只通过30%……第三题居然可以只吃一部分(一直以为要吃完,题目看上去也是这样)第一题因为输入的数极差不大,可以用数组(大小为 (极差1))存放#includeint a[…

avr单片机led数码管六位动态显示时分秒c语言程序,AVR单片机控制8段LED数码管同时显示 - AVR单片机8位数码管显示的程序实现(两种方法介绍)...

AVR单片机控制8段LED数码管同时显示这是一个简单的供单片机入门学习者练习用的8段LED数码管控制汇编程序,控制一个两位的数码管同时显示字符(动态刷新)。用AVR- Studio-4 开发,在AVR单片机Atmega48上调试通过。学习者可以举一反三应用到其他类型的单片机…

C语言程序设计与有限元,C语言与有限元程序设计.pdf

C语言与有限元程序设计.pdfC语言与有限元程序设计叶 又 戚 燕(上海交通大攀国家棋其C几D工程中心 上海加0030) (上海大学计算中心 上海匆印力摘 要 本文通过与FORTRAN77语官的比较,说明利用C语言开发有限元程序的可行性。结果表明,C语官不但完全可以实现FORTRAN77的…

c语言gets n,c语言中gets ,getschar 和fgets 的用法及三者之间的差别

满意答案wkmpbg846推荐于 2018.02.27采纳率:45% 等级:8已帮助:362人gets():原型:char *gets(char *buffer) ;功能:从stdlin中获取获取字符串一直到换行符或者遇到EOF为止,但换行符不被录取,会将换行符替换成‘\0’来…

南工院linux考试题库,操作系统复习题..doc

操作系统复习题.第一章 操作系统概述学习指导:本章主要介绍操作系统的基本概念、特性和分类,从操作系统的地位和作用两个方面给出了操作系统的描述性定义。读者应当注意操作系统程序的特殊性,以及操作系统与硬件和其它软件之间的关系,理解操作…

android电话系统,Android电话系统之-rild.doc

Android电话系统之-rild.docAndroid电话系统之-rildRild是Init进程启动的一个本地服务,这个本地服务并没有使用Binder之类的通讯手段,而是采用了socket通讯这种方式。RIL(Radio Interface Layer)Android 给出了一个ril实现框架。由于Android开发者使用的…

android出现错误,在做一个安卓的一个登陆操作的时候,出现错误

源代码如下:/**//*author Administrator**/package com.example.login;//import org.testng.annotations.Test;//import org.testng.annotations.BeforeClass;//import org.testng.annotations.AfterClass;import io.appium.java_client.AppiumDriver;import io.app…

android中svn插件安装,AndroidSDK安装SVN插件问题解决

工具版本信息:Eclipse4.2ADT23.0Subclipse1.10,插件安装地址:http://subclipse.tigris.org/update_1.10.x问题一报错信息如下:Cannot complete the install because one or more required items could not be found.Software being installed: Subversion Revision Graph 1.1.1…

android 点击空白退出,Android 点击空白处隐藏键盘

方法一:使用android的分发机制(代码稍微有点多)/*** 实现点击空白处,软键盘消失事件* param ev* return*/Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {if (ev.getAction() MotionEvent.ACTION_DOWN) {// 获得当前得到焦点的View&#…

鸿蒙系统的变化,鸿蒙系统没变化的背后

原标题:鸿蒙系统没变化的背后鸿蒙系统发布以后被很多人吐槽,说是没什么变化,和之前体验的安卓系统简直一模一样,真的失望至极。其实,鸿蒙系统还是从底层做出了改变,只不过没有变了界面和运行方式而已。那么…

三星s2 硬刷Android 8,三星T710(GALAXY Tab S2 8.0)一键救砖教程,轻松刷回官方系统...

三星T710(GALAXY Tab S2 8.0)手机变砖了怎么办?对于经常刷机的安卓玩家来说,碰到刷机失败导致三星T710(GALAXY Tab S2 8.0)手机无法启动甚至无法进入recovery都是在所难免的事,这个时候我们就需要用到奇兔线刷大师线刷救砖功能了,它能轻松实…

鸿蒙工业互联网,工业互联网 3D 展示平台

原标题:工业互联网 3D 展示平台项目简介产业园区占地约为 158.46 亩,现有生产车间两栋、研发楼一栋、检测楼一栋、食堂及倒班楼一栋、废品库一栋、门卫室两处、综合站房一处。主要从事电缆、电线的生产与加工。产业园区综合管理平台项目开发内容复杂&…

基于android的交流平台,基于Android的移动学习交流平台的设计与实现

摘要:随着移动互联网技术的不断发展,智能手机的不断普及,现在越来越多的人通过手机等智能设备来进行学习和交流。为了满足教师和学生实时的沟通交流,提高学生的学习兴趣和效率,本文设计了基于Android的移动学习交流系统。本文首先通过Openfire完成了客户端与服务器端…

weex监听android返回键,weex使用手册

Native DOM APIsUpdated time: 14/06/2017Weex 在 JS 引擎中,为每个页面都提供了一套 Native DOM APIs,这套接口和 HTML DOM APIs 非常接近,利用这套接口我们可以通过 JavaScript 控制 native 的渲染逻辑。而且 Weex 上层的 Vue 2.0 也是基于…

lean软件Android有吗,leanchat-android

LeanChat Android 客户端简介LeanChat 是 LeanCloud 实时通信 组件的 Demo,通过该应用你可以学习和了解 LeanCloud 实时通信功能。效果截图Leanchat 项目构成如果你从 github clone 速度很慢,可以从 这里 下载项目源码压缩包。部署创建应用注册并登录 Le…

华为系统10.0是鸿蒙吗,暂时忘记鸿蒙!华为EMUI 10.0发布时间确认:这才是主角...

原标题:暂时忘记鸿蒙!华为EMUI 10.0发布时间确认:这才是主角华为鸿蒙系统由于顶着“自研”的光环,自曝光以来便受到科技圈的追捧,虽并未推出但已经有“众星捧月”的迹象。媒体追逐鸿蒙系统自然是为了热度和流量&#x…

a4纸在html的像素,打印常识:A4纸张在显示器上应该要多少像素?

A4纸的尺寸是210mm*297mm,也就是21.0cm*29.7cm,而1英寸2.54cm,如果屏幕DPI分辨率为72像素/英寸,换算一下:相当于1cm可呈现 (72px/2.54cm) 28.34px下面是一些常用分辨率下A4纸在屏幕上的像素尺寸:分辨率是7…