gpt4 book ai didi

c++ - 字符串下标是关联索引吗?

转载 作者:搜寻专家 更新时间:2023-10-30 23:52:23 24 4
gpt4 key购买 nike

The subscript operator ([]) takes a std::string::size_type value. The operator returns a reference to the character at the given position. The value in the subscript is referred to as "a subscript" pp93 ~ 94 C++ Primer 5ed.

A vector is a collection of objects, all of which have the same type. Evey object in the collection has an associated index, which gives access to that object.pp96 C++ Primer 5ed.

问题:

字符串下标是关联索引吗?如果不是,std::string 类型的下标和集合/vector 的关联索引有什么区别?

最佳答案

将“索引”视为“某项的序号”,而不是将“索引”视为“书中的查找表”。

关于 vector ,他们所说的是可以通过顺序数字索引访问其中的元素:v[0]v[1] 等。

字符串和其中的字符完全相同。

关于c++ - 字符串下标是关联索引吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48544400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com