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

前端 未结 12 969
时光说笑
时光说笑 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:01

    For those talking about doing this in C++ which doesn't necessarily support the C99 extensions, then I heartily recommend boost::format. This makes the size_t type size question moot:

    std::cout << boost::format("Sizeof(Var) is %d\n") % sizeof(Var);
    

    Since you don't need size specifiers in boost::format, you can just worry about how you want to display the value.

提交回复
热议问题