为什么text.size()返回std::size_t而不是std::string::size_type ?



我正在学习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

最新更新