Where do I find the definition of size_t?

前端 未结 9 2153
醉酒成梦
醉酒成梦 2020-11-28 04:37

I see variables defined with this type but I don\'t know where it comes from, nor what is its purpose. Why not use int or unsigned int? (What about other \"similar\" types?

9条回答
  •  -上瘾入骨i
    2020-11-28 05:03

    In minimalistic programs where a size_t definition was not loaded "by chance" in some include but I still need it in some context (for example to access std::vector), then I use that context to extract the correct type. For example typedef std::vector::size_type size_t.

    (Surround with namespace {...} if necessary to make the scope limited.)

提交回复
热议问题