正确的printf格式说明符为size_t:祖%或%的Iu? [英] Correct printf format specifier for size_t: %zu or %Iu?

查看:1377
本文介绍了正确的printf格式说明符为size_t:祖%或%的Iu?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打印出来使用的printf 在C ++中使用Microsoft Visual Studio 2010 为size_t 变量的值(我想用的printf 而不是<< 在这个特定的一块code,所以请不答案告诉我,我应该使用<< 代替)

I want to print out the value of a size_t variable using printf in C++ using Microsoft Visual Studio 2010 (I want to use printf instead of << in this specific piece of code, so please no answers telling me I should use << instead).

据帖子

<一个href=\"http://stackoverflow.com/questions/2125845/platform-independent-size-t-format-specifiers-in-c\">Platform在C独立为size_t格式说明?

正确的独立于平台的方法是使用%祖,但这似乎并没有在Visual Studio中工作。在Visual Studio文档

the correct platform-independent way is to use %zu, but this does not seem to work in Visual Studio. The Visual Studio documentation at

http://msdn.microsoft.com/en-us/库/ vstudio / tcxf1dw6.aspx

告诉我,我必须使用%的Iu (使用大写 I ,而不是小写)。

tells me that I must use %Iu (using uppercase i, not lowercase l).

是微软没有按照这些标准?或者有标准以来C99改变?或者是C和C ++(这似乎很奇怪,我)?

Is Microsoft not following the standards here? Or has the standard been changed since C99? Or is the standard different between C and C++ (which would seem very strange to me)?

推荐答案

Microsoft文档

的HH,J,Z和T长度prefixes不被支持。

The hh, j, z, and t length prefixes are not supported.

据指出,正确的preFIX用于为size_t 是我 - 所以你会使用%的Iu

It states that the correct prefix to use for size_t is I - so you'd use %Iu

这篇关于正确的printf格式说明符为size_t:祖%或%的Iu?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆