1、std::size_t可以存储目标平台下任何类型(包括数组)的最大size,为非负数。sizeof()的返回类型为size_t,通常用于数组索引和循环计数。
2、std::size_t在64位系统定义为unsigned long或者unsigned long long,在32位定义为unsigned int(这样当在32位运行64位的代码时,不必更改,size_t自动重定义,方便代码移植,这也是为什么使用size_t而不用unsigned int,unsigned long的原因,或者说size_t存在的意义)。
3、在对容器索引时,如std::string, std::vector,索引的类型是此类容器提供的成员size_type,size_type为size_t的同义词(synonym)。
//c++源码,_int64相当于long long
#ifdef _WIN64
typedef unsigned __int64 size_t;
typedef __int64 ptrdiff_t;
typedef __int64 intptr_t;
#else
typedef unsigned int size_t;
typedef int ptrdiff_t;
typedef int intptr_t;
#endif
//向量下标索引
std::vector<int> vec_a(3,1);
for(std::vector<int>::size_type i=0;i<vec_a.size();++i)
{
...
}