Search code examples
c++headerincludesize-t

Which header to include for size_t


According to cpprefernece size_tis defined in various headers, namely cstddef , cstdio, cstdlib, cstring, ctime, cuchar and (since C++17) cwchar.

My question is why is there not a single definition of size_t? Which header do I include, if I just want size_t?


Solution

  • My question is why is there not a single definition of size_t?

    There is a single definition for std::size_t. It's just defined in multiple headers since those headers themselves use that definition.

    Which header do I include, if I just want size_t?

    Any of the ones that are specified to define it.

    My choice is typically, <cstddef> because it is very small and has other definitions that I'm likely to need such as std::byte.