C++ vector size types

前端 未结 5 1834
醉话见心
醉话见心 2021-02-12 13:49

I just started learning C++ and have a question about vectors. The book I\'m reading states that if I want to extract the size of a vector of type double (for example), I should

5条回答
  •  时光说笑
    2021-02-12 13:55

    The C++ standard says that a container's size_type is an unsigned integral type, but it doesn't specify which one; one implementation might use unsigned int and another might use unsigned long, for example.

    C++ isn't "shielded" from platform-specific implementation details as much as Java is. The size_type alias helps to shield your code from such details, so it'll work properly regardless of what actual type should be used to represent a vector's size.

提交回复
热议问题