支持HW团队,就支付宝领取下面的红包吧!(2018年3月31前,就几毛,也会几块,可以和其他红包叠加使用),你领取消费,HW有奖励。红包使用无条件限制,有条件请注意是不是有病毒。

小伙伴们,给大家发红包喽!人人可领,领完就能用。祝大家领取的红包金额大大大!#吱口令#长按复制此消息,打开支付宝就能领取!er1OEj73Uj

登入 注册 | 验证
| 搜索
HelloWorld论坛 : > 计算机科学、技术、教学> 编程入门> c、c++基础> [转]Working with the type size_t in the functions prinft, scanf and similar functions
 
 
 
 
类别:其他 阅读:3081 评论:0 时间:六月 3, 2013, 2:33 p.m. 关键字:

 

 来源:http://www.viva64.com/en/k/0023/

To work with size_t, ptrdiff_t, intptr_t and uintptr_t types in the functions like sscanf, printf you may use size specifiers. If you are developing a Windows-application, you may use the size specifier "I". For example:

size_t s = 1;
printf("%Iu", s);
If you are developing a Linux-application, you may use the size specifier "z". For example:

ptrdiff_t s = 1;
printf("%zd", s);
Specifiers are well described in the Wikipedia article "printf".

If you have to maintain the code being ported that supports functions like sscanf, you may use special macros opening into the necessary size specifiers in the format of the command strings. Here is an example of a macro that helps you create ported code for various systems:

// PR_SIZET on Win64 = "I"
// PR_SIZET on Win32 = ""
// PR_SIZET on Linux64 = "z"
// ...
size_t u;
scanf("%" PR_SIZET "u", &u);
printf("%" PR_SIZET "x", u);
References

Lessons on development of 64-bit C/C++ applications. Lesson 10. Pattern 2. Functions with variable number of arguments.
Knowledge Base. Difference between %p and %x.
Knowledge Base. How to correctly print a value of the types __int64, size_t, and ptrdiff_t.

[挂载人]初学MPEG

个人签名--------------------------------------------------------------------------------

Please Login (or Sign Up) to leave a comment