C++中size_t与int类型的区别

the return type of the CString::GetLength() method is int and not size_t, especially if the return type of strlen is size_t.
  The stdlib.h and stddef.h header files define a datatype called size_t which is used to represent the size of an object. Library functions that take sizes expect them to be of type size_t, and the sizeof operator evaluates to size_t.
The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to programming errors, particularly as 64-bit architectures become more prevalent.

  stdlib.h和stddef.h头文件定义了一个称为size_t的数据类型,该数据类型用于表示对象的大小。 占用大小的库函数希望它们的大小为size_t,而sizeof运算符的计算结果为size_t。
size_t的实际类型取决于平台。 一个常见的错误是假定size_t与unsigned int相同,这可能会导致编程错误,尤其是在64位体系结构变得更加流行时。

the return type of the CString::GetLength() method is int and not size_t, especially if the return type of strlen is size_t.
CString :: GetLength()方法的返回类型是int而不是size_t,即使strlen的返回类型是size_t。
  string,size类型为size_t
  cstring,size类型为const int

你可能感兴趣的:(笔记)