How can one print a size_t variable portably using the printf family?

前端 未结 12 949
时光说笑
时光说笑 2020-11-22 05:40

I have a variable of type size_t, and I want to print it using printf(). What format specifier do I use to print it portably?

In 32-bit ma

12条回答
  •  有刺的猬
    2020-11-22 06:05

    Looks like it varies depending on what compiler you're using (blech):

    • gnu says %zu (or %zx, or %zd but that displays it as though it were signed, etc.)
    • Microsoft says %Iu (or %Ix, or %Id but again that's signed, etc.) — but as of cl v19 (in Visual Studio 2015), Microsoft supports %zu (see this reply to this comment)

    ...and of course, if you're using C++, you can use cout instead as suggested by AraK.

提交回复
热议问题