什么是用printf打印为size_t的正确方法是什么? [英] What's the correct way to use printf to print a size_t?
本文介绍了什么是用printf打印为size_t的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为size_t被定义为一个无符号整数,但它的大小取决于你是否是一个32位或64位计算机上。什么是打印出为size_t正确的和可移植的方法?
Size_t is defined as an unsigned integer, but the size of it depends on whether you're on a 32 or 64-bit machine. What's the correct and portable way to print out a size_t?
推荐答案
尝试使用%祖格式字符串
Try using the %zu format string
size_t val = get_the_value();
printf("%zu",val);
在Z部分长度说明它说的论点将在长度size_t型。
The z portion is a length specifier which says the argument will be size_t in length.
源代码 - <一个href=\"http://en.wikipedia.org/wiki/Printf#printf%5Fformat%5Fplaceholders\">http://en.wikipedia.org/wiki/Printf#printf_format_placeholders
这篇关于什么是用printf打印为size_t的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文