Which header should I include for `size_t`?

后端 未结 4 1880
执笔经年
执笔经年 2020-12-03 00:13

According to cppreference.com size_t is defined in several headers, namely





<         


        
4条回答
  •  再見小時候
    2020-12-03 00:59

    Assuming I wanted to minimize the functions and types I was importing I'd go with cstddef as it doesn't declare any functions and only declares 6 types. The others focus on particular domains (strings, time, IO) that may not matter to you.

    Note that cstddef only guarantees to define std::size_t, that is, defining size_t in namespace std, although it may provide this name also in the global namespace (effectively, plain size_t).

    In contrast, stddef.h (which is also a header available in C) guarantees to define size_t in the global namespace, and may also provide std::size_t.

提交回复
热议问题