#include <vector>
#include <string>
using namespace std;
int main()
{
vector<int>::size_type a;
vector<double>::size_type b;
string::size_type c;
}
我在vs2015内把鼠标指针分别指向a,b,c,都是显示为size_t类型,那么既然有了size_t,为何还要size_type呢,而且还分别有这么多作用域下的size_type?说的不都是一回事么
Nowadays, programming is all about portability.
size_t is different on 32-bit and 64-bit systems. size_t is convenient for porting between systems.
You can only use one sentence, using size_type is always correct.
Do you think there is no difference?
size_type is a supporting type (defined in the STL class). In fact, it is an unsigned int type. It only exists for the storage of the length of string and vector class objects.
You can try the result of sizeof.
Let’s take a look at include
size_t definition:
size_type definition: