ObjectiveC的NSLog和Printf语句之间的区别 [英] Difference between NSLog and Printf statement for ObjectiveC
问题描述
我想知道Objective-C中 NSLog
和 Printf
语句之间的区别(对于应用程序)目的......!)
I want to know about the difference between the NSLog
and the Printf
statement in Objective-C (for application purpose...!)
为什么所有开发人员都使用 NSLog
而不是 Printf
?
Why do all developer use NSLog
instead of Printf
?
两者看起来相似,但内部工作有什么不同?
Both look similar, but what is the difference in internal working?
在何时可以区分它们?
推荐答案
-
printf()
是一个C标准库函数,接受一个C字符串常量(const char *
)作为格式参数。printf()
写入stdout。printf()
is a C standard library function, accepting a C string constant (const char *
) as its format argument.printf()
writes to stdout.NSLog()
是一个Foundation函数,接受一个常量NSString作为格式,并具有一个扩展格式说明符集(例如,printf()
不打印由%@
,NSLog()
确实如此)。
NSLog()
还会在打印实际格式之前打印进程名称和日期并写入sdterr。NSLog()
is a Foundation function, accepting a constant NSString as format, and has an extended format specifier set (for example,printf()
does't print objects specified by%@
,NSLog()
does).NSLog()
also prints the process name and date before it prints the actual format and writes to sdterr.基本上,我们可以说
NSLog()
是一个扩展的printf()
Objective-C的样式函数(更准确地说,Cocoa和Cocoa Touch)和特定用途。Basically, we can say that
NSLog()
is an extendedprintf()
Style function for Objective-C (more precisely, Cocoa and Cocoa Touch) and specific purposes.这篇关于ObjectiveC的NSLog和Printf语句之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!