我正在学习c++,目前正在阅读c++ Primer (5th edition)。我是关于std::string
的话题。size
成员返回字符串的长度。书中说(p. 88)
auto len = line.size(); // len has type string::size_type
但是Visual Studio Code将len
标识为具有std::size_t
类型。为什么不同呢?
标识len的类型为
std::size_t
。为什么不同呢?
来自microsoft的basic_string文档:
typedef typename allocator_type::size_type size_type;
评论
等于
allocator_type::size_type
。对于
string
类型,相当于size_t
.
(强调我的)
由此可以看出,对于std::string
,它等价于size_t
。